score:4

useEffect(() => {
    console.log('hi');
    const storedUser = JSON.parse(localStorage.getItem('user'));

    if (storedUser) setUser(storedUser);
},[router.pathname]); // re-run the effect if your location changes, router.pathname or wherever your router stores the current location

Related Query

More Query from same tag