I am receiving this error:
Invalid hook call. Hooks can only be called inside of the body of a function component.
I am using a hook to grab the router location with the function HeaderView() (which alone works fine) and setting state so that I can play around with my components based on the current route.
Here is the composition of my hook:
const Navbar = () => {
const [route, setRoute] = useState("/");
function HeaderView() {
let location = useLocation();
console.log(location.pathname);
setRoute(location.pathname);
return;
}
useEffect(() => {
HeaderView()
}, [route]);
.. rest of the component.
useLocation is a function provided by "react-router-dom"; Everytime I think I have a handle on hooks, there seems to be something else that trips me up, so frustration, thanks for reading.
useLocationto the body ofNavbar...const Navbar = () => { let location = useLocation() ...- Chiller