Files
catalogue_frontend/src/context/useAuth.js
2026-08-12 16:33:39 +05:30

21 lines
726 B
JavaScript

import { createContext, useContext } from 'react';
/*
* The context object and its hook live here, apart from AuthContext.jsx.
*
* That split is what React Fast Refresh needs: a module that exports a
* component alongside non-component values cannot be hot-swapped, so every
* edit to the provider would remount the whole tree and drop the session you
* were testing with. AuthContext.jsx now exports only <AuthProvider>, and the
* hook everything imports lives in this plain module.
*/
export const AuthContext = createContext(null);
export function useAuth() {
const context = useContext(AuthContext);
if (!context) {
throw new Error('useAuth must be used within an AuthProvider');
}
return context;
}