about summary refs log tree commit diff
path: root/src/lib/hooks/useSetTitle.ts
blob: 85ba44d29916889b1d45f983e1e3d65709e026f6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import {useEffect} from 'react'
import {useNavigation} from '@react-navigation/native'

import {NavigationProp} from 'lib/routes/types'
import {bskyTitle} from 'lib/strings/headings'
import {useUnreadCountLabel} from './useUnreadCountLabel'

export function useSetTitle(title?: string) {
  const navigation = useNavigation<NavigationProp>()
  const unreadCountLabel = useUnreadCountLabel()
  useEffect(() => {
    if (title) {
      navigation.setOptions({title: bskyTitle(title, unreadCountLabel)})
    }
  }, [title, navigation, unreadCountLabel])
}