arrow_backBACK TO DRILLS
Black Beltrules-of-hooksPREMIUM
useContext Cannot Be Called Outside a React Component - Including Route Loader Functions
A React Router loader function needs to read authentication state before a route renders.
REACT_MODULE // 0x42
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?