Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Load Preferences

Loads a value from the preference store with type safety and automatic JSON deserialization.

Parameters

  • key (string) - The unique identifier for the stored data

Returns

Promise<V> - A promise that resolves to the deserialized value of the specified type

Description

The load() function retrieves and deserializes data that was previously saved with the same key. The data is automatically parsed from JSON format back to the original type. If the key does not exist or cannot be parsed, the function will throw an error.

Examples

Basic Data Loading

import {preferences} from '@homunculus/sdk';

// Load simple values
const username = await preferences.load<string>('username');
const volume = await preferences.load<number>('audio-volume');
const isFirstRun = await preferences.load<boolean>('first-run');

console.log(`Welcome back, ${username}!`);