about summary refs log tree commit diff
path: root/src/lib/hooks/useUnreadCountLabel.ts
blob: e2bf77885d59abc41e86aa267d941f23eb0164e1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import {useEffect, useReducer} from 'react'
import {DeviceEventEmitter} from 'react-native'
import {useStores} from 'state/index'

export function useUnreadCountLabel() {
  // HACK: We don't have anything like Redux selectors,
  // and we don't want to use <RootStoreContext.Consumer />
  // to react to the whole store
  const [, forceUpdate] = useReducer(x => x + 1, 0)
  useEffect(() => {
    const subscription = DeviceEventEmitter.addListener(
      'unread-notifications',
      forceUpdate,
    )
    return () => subscription?.remove()
  }, [forceUpdate])

  return useStores().me.notifications.unreadCountLabel
}