introducing userContext

This commit is contained in:
Antoine M 2024-02-01 18:26:47 +01:00
parent 0df0a90e73
commit ed667c0c1a
2 changed files with 44 additions and 0 deletions

View File

@ -0,0 +1,38 @@
import { createContext, useState } from "react";
export const UserContext = createContext({
language: "fr",
country: "Belgique",
profile: "lhoist_employee",
changeLanguage: () => {},
changeCountry: () => {},
changeProfile: () => {},
});
export function UserContextProvider({ children }) {
const [language, setLanguage] = useState("fr");
const [country, setCountry] = useState({ name: "belgique", iso: "BE" });
const [profile, setProfile] = useState("lhoist_employee");
function changeLanguage() {
if (language === "fr") {
setLanguage("en");
} else {
setLanguage("fr");
}
}
function changeCountry(newCountry) {
setCountry(newCountry);
}
function changeProfile(newProfile) {
setProfile(newProfile);
}
return (
<UserContext.Provider
value={{ language, changeLanguage, country, changeCountry, profile, changeProfile }}>
{children}
</UserContext.Provider>
);
}

View File

@ -0,0 +1,6 @@
import { useContext } from "react";
import { UserContext } from "../context/UserContext";
export function useUserContext() {
return useContext(UserContext);
}