title: Use of useEffect with useLocation
body: <p>I want to know what is the biggest difference between using (or not) useEffect to update useLocation.</p>
  <p>I usually find people set useLocation inside useEffect to update the state whenever the URL's path changes, but I found I don't need to do this to have the location to be updated.</p>
  <pre><code>const NavBar = () =&gt; {
    const location = useLocation();
    const [currentPath, setCurrentPath] = useState('')
  
    const location = useLocation();
    console.log('pathname:', location.pathname)
  
     useEffect(() =&gt; {
       setCurrentPath(location.pathname);
     }, [location]);
  
  console.log('currentPath:', currentPath)
  ...
  }
  </code></pre>
  <pre><code>Returns
  pathname: /results:Cancer
  currentPath: /results:Cancer
  </code></pre>
  <p>I mean, the only difference I find is that with useEffect the return will happen after the component mounts. I'm trying to understand the best practices to become a better programmer.</p>