Files
HKSingleParty/99_references/ionic-react-conference-app-main_old/src/data/AppContext.tsx
2025-05-28 09:55:51 +08:00

30 lines
653 B
TypeScript

import React, { createContext, PropsWithChildren, useReducer } from 'react';
import { initialState, AppState, reducers } from './state';
export interface AppContextState {
state: AppState;
dispatch: React.Dispatch<any>;
}
export const AppContext = createContext<AppContextState>({
state: initialState,
dispatch: () => undefined,
});
export const AppContextProvider: React.FC<PropsWithChildren> = ({
children,
}) => {
const [store, dispatch] = useReducer(reducers, initialState);
return (
<AppContext.Provider
value={{
state: store,
dispatch,
}}
>
{children}
</AppContext.Provider>
);
};