New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More

@rickbrown/use-local-storage

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@rickbrown/use-local-storage

A custom React hook to simplify using local storage.

1.0.2
latest
Version published
Weekly downloads
6
-53.85%
Maintainers
1
Weekly downloads
 
Created

@rickbrown/use-local-storage

NPM JavaScript Style Guide

Description

useLocalStorage is a custom React hook, which simplifies using the browsers local storage, when developing React applications.

Installation

Use the package manager yarn to install the useLocalStorage hook.

yarn add @rickbrown/use-local-storage

Usage

import { useLocalStorage } from '@rickbrown/use-local-storage'

const Example = () => {
  // Optionally accepts 2 arguments for its initial value.
  // ('key','value')
  const [name, setName] = useLocalStorage()
  
  const [newName, setNewName] = React.useState('')

  return (
    <div>
      <p>Current value in local storage: {name}</p>
      <input
        type="text"
        placeholder="Enter your name"
        value={newName}
        onChange={e => setNewName(e.target.value)}
      />
      <button onClick={() => setName(newName)}>
        Click To Update Local Storage
      </button>
    </div>
  )
}

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

MIT

FAQs

Package last updated on 19 Dec 2019

Did you know?

Socket

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