Created the UserProvider.jsx context

This commit is contained in:
Mathias Wagner 2023-11-13 13:10:07 +01:00
parent ccfce62af2
commit 4b455f01b3
Signed by: Mathias
GPG Key ID: B8DC354B0A1F5B44
2 changed files with 21 additions and 0 deletions

View File

@ -0,0 +1,20 @@
import {createContext, useEffect, useState} from "react";
import {jsonRequest} from "@/common/util/RequestUtil.js";
export const UserContext = createContext({});
export const UserProvider = ({children}) => {
const [user, setUser] = useState(null);
const updateUser = async () => jsonRequest("/user/@me").then((res) => setUser(res));
useEffect(() => {
updateUser();
}, []);
return (
<UserContext.Provider value={user}>
{children}
</UserContext.Provider>
)
}

View File

@ -0,0 +1 @@
export * from "./UserProvider.jsx";