Skip to content

progfay/use-local-storage

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

useLocalStorage(key) hooks

⚠️ This code has not yet been published in npm registry.

import {
  setlocalStorageItem,
  useLocalStorage,
} from '@progfay/use-local-storage'

const KEY = 'RANDOM_VALUE'

const ComponentA = () => (
  <button onClick={() => setLocalStorageItem(Math.random().toFixed(10))}>
    Set random value for localStorage
  </button>
)

const ComponentB = () => {
  const randomValue = useLocalStorage(KEY)
  return (
    <p>
      random value in localStorage: {randomValue}
    </p>
  )
}

const App = () => (
  <>
    <ComponentA />
    <ComponentB />
  </>
)

About

React hooks to manage state that works with `localStorage`

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published