title: React router v6 history.listen
body: <p>In React Router v5 there was a listen mehtode on the history object.
  With the method I wrote a usePathname hook to rerender a component on a path change.
  In React Router v6, this method no longer exists. Is there an alternative for something like this? I would hate to use useLocation because it also renders if the state changes, which I don't need in this case.</p>
  <p>The hook is used with v5.</p>
  <pre><code>import React from &quot;react&quot;;
  import { useHistory } from &quot;react-router&quot;;
  
  export function usePathname(): string {
    let [state, setState] = React.useState&lt;string&gt;(window.location.pathname);
  
    const history = useHistory();
    React.useLayoutEffect(
      () =&gt;
        history.listen((locationListener) =&gt; setState(locationListener.pathname)),
      [history]
    );
    return state;
  }
  </code></pre>