All files / src/store ShowTools.tsx

100% Statements 13/13
100% Branches 0/0
83.33% Functions 5/6
100% Lines 12/12

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          22x 22x   34x         22x 1307x     22x 22x     123x       1220x               22x 123x           22x  
import { FC, PropsWithChildren, createContext, useContext, useReducer } from 'react';
 
type InitialState = Record<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 useShowToolsStore = () => {
  return useContext(Context);
};
 
const DispatchShowTools = createContext<Dispatch>(() => {});
DispatchShowTools.displayName = 'JVR.DispatchShowTools';
 
export function useShowTools() {
  return useReducer(reducer, initialState);
}
 
export function useShowToolsDispatch() {
  return useContext(DispatchShowTools);
}
 
interface ShowToolsProps {
  initial: InitialState;
  dispatch: Dispatch;
}
 
export const ShowTools: FC<PropsWithChildren<ShowToolsProps>> = ({ initial, dispatch, children }) => {
  return (
    <Context.Provider value={initial}>
      <DispatchShowTools.Provider value={dispatch}>{children}</DispatchShowTools.Provider>
    </Context.Provider>
  );
};
ShowTools.displayName = 'JVR.ShowTools';