src/useHistoryUpdate.js
// Listens to the history object for changes and forces the component to re-render
Listens to the history object for changes and forces the component to re-render
Listens to the history object for changes and forces the component to re - render
function useHistoryUpdate (history) {
  const [, forceUpdate] = useReducer(x => x + 1, 0)
  useEffect(() => {
    return history.listen(() => {
      forceUpdate()
    })
  }, [history])
}
function useHistoryUpdate ( history ) { const [ , forceUpdate ] = useReducer ( x => x + 1 , 0 ) useEffect ( ( ) => { return history . listen ( ( ) => { forceUpdate ( ) } ) } , [ history ] ) }
Listens to the history object for changes and forces the component to re-render
Listens to the history object for changes and forces the component to re - render
// history.listen returns an 'unlisten' function which we return here so it is called by useEffect() cleanup