Initial commit

This commit is contained in:
JustSong
2023-04-22 20:39:27 +08:00
committed by GitHub
commit ab1f8a2bf4
87 changed files with 6933 additions and 0 deletions

View File

@@ -0,0 +1,19 @@
// contexts/User/index.jsx
import React from "react"
import { reducer, initialState } from "./reducer"
export const UserContext = React.createContext({
state: initialState,
dispatch: () => null
})
export const UserProvider = ({ children }) => {
const [state, dispatch] = React.useReducer(reducer, initialState)
return (
<UserContext.Provider value={[ state, dispatch ]}>
{ children }
</UserContext.Provider>
)
}

View File

@@ -0,0 +1,21 @@
export const reducer = (state, action) => {
switch (action.type) {
case 'login':
return {
...state,
user: action.payload
};
case 'logout':
return {
...state,
user: undefined
};
default:
return state;
}
};
export const initialState = {
user: undefined
};