useEffect doesn't update state on route change
The effect you want is "When the location change then update my state", this is translated in useEffect
code like this :
useEffect(() => {
detectHome();
return () => {
detectHome();
};
}, [location]);