2023-04-22 20:39:27 +08:00
|
|
|
// contexts/User/index.jsx
|
|
|
|
|
|
2024-03-23 21:24:39 +08:00
|
|
|
import React from 'react';
|
|
|
|
|
import { reducer, initialState } from './reducer';
|
2023-04-22 20:39:27 +08:00
|
|
|
|
|
|
|
|
export const UserContext = React.createContext({
|
|
|
|
|
state: initialState,
|
2024-03-23 21:24:39 +08:00
|
|
|
dispatch: () => null,
|
|
|
|
|
});
|
2023-04-22 20:39:27 +08:00
|
|
|
|
|
|
|
|
export const UserProvider = ({ children }) => {
|
2024-03-23 21:24:39 +08:00
|
|
|
const [state, dispatch] = React.useReducer(reducer, initialState);
|
2023-04-22 20:39:27 +08:00
|
|
|
|
|
|
|
|
return (
|
2024-03-23 21:24:39 +08:00
|
|
|
<UserContext.Provider value={[state, dispatch]}>
|
|
|
|
|
{children}
|
2023-04-22 20:39:27 +08:00
|
|
|
</UserContext.Provider>
|
2024-03-23 21:24:39 +08:00
|
|
|
);
|
|
|
|
|
};
|