Skip to content

Instantly share code, notes, and snippets.

View reed-jones's full-sized avatar

Reed Jones reed-jones

View GitHub Profile
@coreyward
coreyward / README.md
Last active November 7, 2021 09:39
I wrote this hook to persist a simple user settings (think dark mode) to local storage in a cross-tab compatible way.

useStorage React Hook

Similar to useState but with some lightweight behind-the-scenes writing to localStorage; also subscribes to changes in localStorage to allow for cross-tab changes to sync automatically.

Example Usage

The first argument is the name of the local storage property/key you want to control with this hook. The second argument, options, really just has one available directive: bool. Setting bool to true has the effect of evaluating the data