Created the UserProvider.jsx context
This commit is contained in:
parent
ccfce62af2
commit
4b455f01b3
20
src/states/Manage/contexts/UserProvider/UserProvider.jsx
Normal file
20
src/states/Manage/contexts/UserProvider/UserProvider.jsx
Normal 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>
|
||||
)
|
||||
}
|
1
src/states/Manage/contexts/UserProvider/index.js
Normal file
1
src/states/Manage/contexts/UserProvider/index.js
Normal file
@ -0,0 +1 @@
|
||||
export * from "./UserProvider.jsx";
|
Loading…
x
Reference in New Issue
Block a user