localState
Category State
A state that is synced with local storage.
Demo
Search :
Try opening the page in another tab after searching
Usage
<script>
import { localState } from '@sv-use/core';
const counter = localState('counter', 0);
</script>
<span>counter : {counter.current}</span>
Type Definitions
type LocalStateOptions<T> = {
/** Defaults to `JSON.stringify`. */
serialize?: (value: T) => string;
/** Defaults to `JSON.parse`. */
deserialize?: (value: string) => T;
/** If the key is present in local storage, override that value or not. */
overrideDefault?: boolean;
};
/**
* A state that is synced with local storage.
* @param key The key to use in local storage.
* @param value The initial value of the state.
* @param options Additional options to customize the behavior.
* @returns A reactive `current` property.
* @see https://svelte-librarian.github.io/sv-use/docs/core/local-state
*/
export declare function localState<T>(key: string, value: T, options?: LocalStateOptions<T>): {
current: T;
};
export {};