Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | 22x 22x 22x 22x 476x 22x 22x 123x 119x 22x 123x 22x | import { FC, PropsWithChildren, createContext, useContext, useReducer } from 'react';
type InitialState = {
[key: string]: boolean;
};
type Dispatch = React.Dispatch<InitialState>;
const initialState: InitialState = {};
const Context = createContext<InitialState>(initialState);
const reducer = (state: InitialState, action: InitialState) => ({
...state,
...action,
});
export const useExpandsStore = () => {
return useContext(Context);
};
const DispatchExpands = createContext<Dispatch>(() => {});
DispatchExpands.displayName = 'JVR.DispatchExpands';
export function useExpands() {
return useReducer(reducer, initialState);
}
export function useExpandsDispatch() {
return useContext(DispatchExpands);
}
interface ExpandsProps {
initial: InitialState;
dispatch: Dispatch;
}
export const Expands: FC<PropsWithChildren<ExpandsProps>> = ({ initial, dispatch, children }) => {
return (
<Context.Provider value={initial}>
<DispatchExpands.Provider value={dispatch}>{children}</DispatchExpands.Provider>
</Context.Provider>
);
};
Expands.displayName = 'JVR.Expands';
|