import { Dispatch } from 'react'; import { AppSharedState } from '../appState/state.models'; import { OneOfStateActions } from '../appState/state.models.actions'; /** * Hook exposing shared app state + a (stable) dispatch with optional logging. * * Issue (root cause of previous crash): * - Earlier "logger" version wrapped the original context dispatch in an inline function on every render. * - Components (e.g. map setup) had `dispatch` in a `useEffect` dependency array. * - Each render produced a new function identity ⇒ effect re-ran unnecessarily. * - Cleanup of the previous effect removed maps / mapSets before the new effect finished re‑adding them. * - Concurrently, other actions expected the map to exist ⇒ `Map with key ... not found`. * - React 18 StrictMode double invoke on mount amplified the window where state was inconsistent. * * Fixes applied here: * 1. `dispatchWithLog` wrapped in `useCallback` ⇒ stable identity unless logging flag or underlying dispatch changes. * 2. Returned tuple `[state, dispatch]` memoized with `useMemo` ⇒ consumer effects not retriggered by wrapper recreation. * 3. Previous state stored in a ref for before/after logging without causing re-renders. * * Logging behavior: * - Before dispatch: prints previous state + action (when enabled). * - After render (state change observed): prints current state. * * Safe usage: * const [state, dispatch] = useSharedState(true); // enable logging */ export declare const useSharedState: (logSharedState?: boolean) => [AppSpecificState, Dispatch];