···2828import {useColorSchemeStyle} from 'lib/hooks/useColorSchemeStyle'
2929import {router} from './routes'
3030import {usePalette} from 'lib/hooks/usePalette'
3131-import {useUnreadCountLabel} from 'lib/hooks/useUnreadCountLabel'
3231import {useStores} from './state'
33323433import {HomeScreen} from './view/screens/Home'
···296295 * The FlatNavigator is used by Web to represent the routes
297296 * in a single ("flat") stack.
298297 */
299299-function FlatNavigator() {
298298+const FlatNavigator = observer(() => {
300299 const pal = usePalette('default')
301301- const unreadCountLabel = useUnreadCountLabel()
300300+ const unreadCountLabel = useStores().me.notifications.unreadCountLabel
302301 const title = (page: string) => bskyTitle(page, unreadCountLabel)
303302 return (
304303 <Flat.Navigator
···327326 {commonScreens(Flat as typeof HomeTab, unreadCountLabel)}
328327 </Flat.Navigator>
329328 )
330330-}
329329+})
331330332331/**
333332 * The RoutesContainer should wrap all components which need access
+6-2
src/lib/hooks/useSetTitle.ts
···3344import {NavigationProp} from 'lib/routes/types'
55import {bskyTitle} from 'lib/strings/headings'
66-import {useUnreadCountLabel} from './useUnreadCountLabel'
66+import {useStores} from 'state/index'
7788+/**
99+ * Requires consuming component to be wrapped in `observer`:
1010+ * https://stackoverflow.com/a/71488009
1111+ */
812export function useSetTitle(title?: string) {
913 const navigation = useNavigation<NavigationProp>()
1010- const unreadCountLabel = useUnreadCountLabel()
1414+ const {unreadCountLabel} = useStores().me.notifications
1115 useEffect(() => {
1216 if (title) {
1317 navigation.setOptions({title: bskyTitle(title, unreadCountLabel)})
-19
src/lib/hooks/useUnreadCountLabel.ts
···11-import {useEffect, useReducer} from 'react'
22-import {DeviceEventEmitter} from 'react-native'
33-import {useStores} from 'state/index'
44-55-export function useUnreadCountLabel() {
66- // HACK: We don't have anything like Redux selectors,
77- // and we don't want to use <RootStoreContext.Consumer />
88- // to react to the whole store
99- const [, forceUpdate] = useReducer(x => x + 1, 0)
1010- useEffect(() => {
1111- const subscription = DeviceEventEmitter.addListener(
1212- 'unread-notifications',
1313- forceUpdate,
1414- )
1515- return () => subscription?.remove()
1616- }, [forceUpdate])
1717-1818- return useStores().me.notifications.unreadCountLabel
1919-}