Skip to content

Instantly share code, notes, and snippets.

@pwener
Created September 27, 2019 02:07
Show Gist options
  • Select an option

  • Save pwener/9dc22d5361153f22a409eefe2752b801 to your computer and use it in GitHub Desktop.

Select an option

Save pwener/9dc22d5361153f22a409eefe2752b801 to your computer and use it in GitHub Desktop.
Get changes of pathname using history in React functional
const [pathname, setPathname] = useState(history.location.pathname);
useEffect(() => {
history.listen((location) => {
setPathname(location.pathname);
});
}, []);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment