This module is a little helper, primarily intended for use with react. A minimal persisted state libary that conforms to and extends the useState api.
- Seamlessly supports async storage engines by returning pending as the last item in the return tuple. Value will be default until storage is resolved.
- Seamlessly supports sync storage engines, in a single render pass.
- Can use setPersistedState / getPersistedState directly if use is needed outside of hook
- Optionally syncs cross-tab (if on web)
// hook
let [theme, setTheme, themePending] = usePersistedState('theme-key', 'dark')
// getter
let theme = await getPersistedState('theme-key')