Untitled
unknown
plain_text
10 months ago
614 B
7
Indexable
import React, { createContext, useState, useContext } from 'react'; const AuthContext = createContext(); export const AuthProvider = ({ children }) => { const [isAuthenticated, setIsAuthenticated] = useState(false); const login = (username, password) => { if (username === 'admin' && password === 'admin') { setIsAuthenticated(true); } }; const logout = () => { setIsAuthenticated(false); }; return ( <AuthContext.Provider value={{ isAuthenticated, login, logout }}> {children} </AuthContext.Provider> ); }; export const useAuth = () => useContext(AuthContext);
Editor is loading...
Leave a Comment