# use-persisted-value **Repository Path**: mirrors_fmoo/use-persisted-value ## Basic Information - **Project Name**: use-persisted-value - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2022-07-03 - **Last Updated**: 2026-05-17 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # use-persisted-value ## Installation ``` yarn add https://github.com/xyin96/use-persisted-value ``` ## Usage ### usePersistedValue We also keep a list of subscribers, so any mounted react components that use this hook will be notified of the update if you call `setTheme`. ``` import * as React from 'react'; import {usePersistedValue} from 'use-persisted-value'; function MyComponent() { const [theme, setTheme] = usePersistedValue('ui:theme'); if (theme == null) { // not yet loaded return null; } // render ui return } ``` ### prefetchKey ``` import {prefetchKey} from 'use-persisted-value'; function loadResources() { return Promise.all([ prefetchKey('ui:theme'), ]); } ``` ### setKey ``` import {setKey} from 'use-persisted-value'; function clearTheme() { return Promise.all([ setKey('ui:theme', 'light'), ]); } ``` ## How does this differ from Context? This is not a replacement for Context. Context API is good for *React Hierarchy scoped variables* such as form state, theming, etc. But this lets you create global *singleton* variables that React Components can *subscribe* to, and retain its value between app starts.