import { useEffect , useState } from 'react' ; import { _document } from '../_ssr.config' ; import { useMount } from '../useMount' ; import { useMutationObserver } from '../useMutationObserver' ; param newTitle see https export function useTitle ( newTitle ? ) { const [ title , setTitle ] = useState ( newTitle ?? '' ) ; useMount ( ( ) => { setTitle ( ( newTitle || _document ?. title ) ?? '' ) ; } ) ; useEffect ( ( ) => { document . title = title ; } , [ title ] ) ; useMutationObserver ( _document ?. head . querySelector ( 'title' ) , ( ) => { if ( document . title !== title ) setTitle ( document . title ) ; } , { childList : true } ) ; return { title , setTitle } ; }