Updated frontend
This commit is contained in:
20
src/context/useAuth.js
Normal file
20
src/context/useAuth.js
Normal file
@@ -0,0 +1,20 @@
|
||||
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;
|
||||
}
|
||||
Reference in New Issue
Block a user