Skip to content

Commit

Permalink
Merge branch 'dev' of github.com:Dreallers/WildTube into recupConnexion
Browse files Browse the repository at this point in the history
  • Loading branch information
Aurelemeriau committed Dec 21, 2023
2 parents a2329b9 + 0241326 commit eb5db6b
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions frontend/src/contexts/UserContext.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { createContext, useContext, useState, useMemo } from "react";
import { PropTypes } from "prop-types";

const UserContext = createContext();

export function UserProvider({ children }) {
const [user, setUser] = useState(null);

const updateUser = (newUser) => {
setUser(newUser);
};
const contexValue = useMemo(() => {
return { user, updateUser };
}, [user, updateUser]);

return (
<UserContext.Provider value={contexValue}>{children}</UserContext.Provider>
);
}

export const useUser = () => {
return useContext(UserContext);
};

UserProvider.propTypes = {
children: PropTypes.oneOfType([
PropTypes.arrayOf(PropTypes.node),
PropTypes.node,
]).isRequired,
};

0 comments on commit eb5db6b

Please sign in to comment.