Slide 20
Slide 20 text
mount — subscribe, unmount — unsubscribe
const useLocation = () => {
const [location, setLocation] = useState(location.pathname);
// call `setLocation` whenever the pathname changes
useEffect(() => {
// subscribe to pushState/replaceState
return () => { /* unsub */ }
}, []);
return [location, to => history.pushState(0, 0, to)];
};