MCPcopy Create free account
hub / github.com/HelloCSV/HelloCSV / ReducerProvider

Function ReducerProvider

src/importer/reducer.tsx:229–264  ·  view source on GitHub ↗
({
  sheets,
  persistenceConfig,
  initialState,
  onStateChanged,
  children,
}: {
  sheets: SheetDefinition[];
  persistenceConfig: PersistenceConfig;
  initialState?: ImporterState;
  onStateChanged?: (prev: ImporterState, next: ImporterState) => void;
  children: ReactNode;
})

Source from the content-addressed store, hash-verified

227);
228
229export function ReducerProvider({
230 sheets,
231 persistenceConfig,
232 initialState,
233 onStateChanged,
234 children,
235}: {
236 sheets: SheetDefinition[];
237 persistenceConfig: PersistenceConfig;
238 initialState?: ImporterState;
239 onStateChanged?: (prev: ImporterState, next: ImporterState) => void;
240 children: ReactNode;
241}) {
242 const [state, dispatch] = usePersistedReducer(
243 sheets,
244 persistenceConfig,
245 initialState
246 );
247
248 const previousStateRef = useRef(state);
249
250 useEffect(() => {
251 if (previousStateRef.current !== state) {
252 onStateChanged?.(previousStateRef.current, state);
253 previousStateRef.current = state;
254 }
255 }, [state, onStateChanged]);
256
257 return (
258 <ImporterStateContext.Provider value={state}>
259 <ImporterStateDispatchContext.Provider value={dispatch}>
260 {children}
261 </ImporterStateDispatchContext.Provider>
262 </ImporterStateContext.Provider>
263 );
264}
265
266export function useImporterState(): ImporterState {
267 return useContext(ImporterStateContext);

Callers

nothing calls this directly

Calls 1

usePersistedReducerFunction · 0.85

Tested by

no test coverage detected