Files
bsky-social-app/src/lib/hooks/useSetTitle.ts
T
LW 41f3a05515 style: remove useUnreadCountLabel hack from 50c1841 (#655) (#686)
I just realized how `mobx` works (never used before lol) and now I feel
dumb.
2023-05-17 09:50:28 -05:00

21 lines
650 B
TypeScript

import {useEffect} from 'react'
import {useNavigation} from '@react-navigation/native'
import {NavigationProp} from 'lib/routes/types'
import {bskyTitle} from 'lib/strings/headings'
import {useStores} from 'state/index'
/**
* Requires consuming component to be wrapped in `observer`:
* https://stackoverflow.com/a/71488009
*/
export function useSetTitle(title?: string) {
const navigation = useNavigation<NavigationProp>()
const {unreadCountLabel} = useStores().me.notifications
useEffect(() => {
if (title) {
navigation.setOptions({title: bskyTitle(title, unreadCountLabel)})
}
}, [title, navigation, unreadCountLabel])
}