title: React hooks - remove from react-router location state when we refresh page
body: <p>When I am entering one page of the app I pass data through location state using react-router. Then I access it via <code>location.state.myDataObject</code>. When I refresh the page it is still there, while I would like it to be empty. Here's what I've try to use:</p>
  <pre><code>  const resetLocation = () =&gt; {
      history.replace({
        ...location,
        state: undefined,
      });
    };
  
    useEffect(() =&gt; {
      window.addEventListener('onbeforeunload', resetLocation);
    }, []);
  </code></pre>
  <p>Or adding it to <code>unmount</code> action within <code>useEffect</code> but I guess it is not called when refreshing the page:</p>
  <pre><code>  useEffect(() =&gt; {
      return function cleanLocationState() {
        history.replace({
          ...this.props.location,
          state: undefined,
        });
      };
    }, []);
  </code></pre>