# usePersistentState A state hook that persists its value in the `localStorage`. It provides the functionality to synchronize state with the browser's storage, ensuring the state persists across page reloads. ## Usage ```tsx import { usePersistentState } from '@gilbarbara/hooks'; function Component() { const [state, setState, remove] = usePersistentState('my-key', { foo: 'bar', baz: 'qux' }); return (
Value: {JSON.stringify(state, null, 2)}
); } ``` ## Reference ```typescript interface UsePersistentStateOptions { /** * Check if the saved state keys are different from the initial state and override it if needed. * @default false */ overrideDivergentSavedState?: boolean; /** * Reset properties in the saved state. */ resetProperties?: Partial; } type UsePersistentStateResult = [ state: T, setState: Dispatch>, remove: () => void, ]; export function usePersistentState( key: string, initialState: TState, options?: UsePersistentStateOptions, ): UsePersistentStateResult ```