({
sheets,
persistenceConfig,
initialState,
onStateChanged,
children,
}: {
sheets: SheetDefinition[];
persistenceConfig: PersistenceConfig;
initialState?: ImporterState;
onStateChanged?: (prev: ImporterState, next: ImporterState) => void;
children: ReactNode;
})
| 227 | ); |
| 228 | |
| 229 | export 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 | |
| 266 | export function useImporterState(): ImporterState { |
| 267 | return useContext(ImporterStateContext); |
nothing calls this directly
no test coverage detected