ffsaf-site/src/main/webapp/src/hooks/useExternalWindow.jsx

33 lines
867 B
JavaScript

import {createContext, useContext, useReducer} from "react";
const PubAffContext = createContext({next: [], c1: undefined, c2: undefined, showScore: true});
const PubAffDispatchContext = createContext(() => {
});
function reducer(state, action) {
switch (action.type) {
case 'SET_DATA':
return {...state, ...action.payload}
default:
return state
}
}
export function PubAffProvider({children}) {
const [state, dispatch] = useReducer(reducer, {})
return <PubAffContext.Provider value={state}>
<PubAffDispatchContext.Provider value={dispatch}>
{children}
</PubAffDispatchContext.Provider>
</PubAffContext.Provider>
}
export function usePubAffState() {
return useContext(PubAffContext)
}
export function usePubAffDispatch() {
return useContext(PubAffDispatchContext)
}