sessionState

Category States

A state that is synced with session storage.

Demo

Search :

Try reloading the page after searching

Usage

<script>
	import { sessionState } from '@sv-use/core';
 
	const counter = sessionState('counter', 0);
</script>
 
<span>counter : {counter.current}</span>
Type definitions
type SessionStateOptions<T> = {
    /** Defaults to `JSON.stringify`. */
    serialize?: (value: T) => string;
    /** Defaults to `JSON.parse`. */
    deserialize?: (value: string) => T;
    /** If the key is present in session storage, override that value or not. */
    overrideDefault?: boolean;
};
/**
 * A state that is synced with session storage.
 * @param key The key to use in session 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/states/session-state
 */
export declare function sessionState<T>(key: string, value: T, options?: SessionStateOptions<T>): {
    current: T;
};
export {};

Sources