arrow_backBACK TO DRILLS
Black Belt - Hardrules-of-hooksPREMIUM
Calling useContext Inside a React Router Loader
A React Router loader function needs to read authentication state before a route renders.
//REACT_MODULE
export async function loader() {
const auth = useContext(AuthContext);
if (!auth.user) throw redirect('/login');
return null;
}Why does calling useContext here throw an invalid hook call error instead of returning the current auth value?