UNPKG

@25sprout/react-starter

Version:

25sprout web starter with React

19 lines (13 loc) 433 B
import { useState, useEffect } from 'react'; import { History, Location } from 'history'; const useLocation = (history: History): Location => { const [location, setLocation] = useState<Location>(history.location); useEffect(() => { const unlisten = history.listen(({ location: newLocation }) => { setLocation(newLocation); }); return () => unlisten(); }, [history]); return location; }; export default useLocation;