Socket
Socket
Sign inDemoInstall

just-storage-hooks

Package Overview
Dependencies
8
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    just-storage-hooks

Some storage hooks


Version published
Maintainers
1
Created

Readme

Source

Just Storage Hooks

Do you have an input or checkbox you'd like to recover after a reload? Do you need to store your app's configuration page?

Just use storage hooks with localStorage to ensure data is fresh on the first hook call.

Installation

npm i just-storage-hooks

Methods

useStorage

Read and write to localStorage.

Optional mutate function allows for storeState data to be altered before storing. This should be memo'd or unchanged between hooks.

const mutate = useCallback(data => `${data}`);
const [state, storeState] = useStorage(key, mutate);

useDebounceCallback

Debounce a callback when state changes. Used to avoid thrashing localStorage in the following hooks

const callback = useCallback((data) => { console.log(data); });
useDebounceCallback(state, callback, 10);

useStorageState

Like useState but with localStorage when first starting the effect

const [state, setState] = useStorageState('key', { some: 'state' }, optionalMutate);

useStorageReducer

Like useReducer but with localStorage when first starting the effect

const [state, dispatch] = useStorageReducer('key', reducer, { some: 'state' }, optionalMutate);

License

Copyright (c) 2021, Michael Szmadzinski. (MIT License)

FAQs

Last updated on 25 Nov 2023

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc