@reacthooks.org/use-local-storage

1.0.7 • Public • Published

Install

$ npm install @reacthooks.org/use-local-storage

useLocalStorage

A React Hook which sets/gets a value in window.localStorage.

Synopsis

In your React component:

import { useState } from 'react'
import useLocalStorage from "use-local-storage"

function Skeleton() {
  // set the value in localStorage upon initialisation
  const [ salutation, setSalutation ] = useLocalStorage("salutation", "Hello")

  // don't set the value but instead retrieve what is in localStorage()
  const [ name, setName ] = useLocalStorage("name")

  return <p>{ salutation } { name }</p>
}

Other Hooks

Please see all of the other reacthooks.org hooks:

Author

$ npx chilts

   ╒════════════════════════════════════════════════════╕
   │                                                    │
   │   Andrew Chilton (Personal)                        │
   │   -------------------------                        │
   │                                                    │
   │          Email : andychilton@gmail.com             │
   │            Web : https://chilts.org                │
   │        Twitter : https://twitter.com/andychilton   │
   │         GitHub : https://github.com/chilts         │
   │         GitLab : https://gitlab.org/chilts         │
   │                                                    │
   │   Apps Attic Ltd (My Company)                      │
   │   ---------------------------                      │
   │                                                    │
   │          Email : chilts@appsattic.com              │
   │            Web : https://appsattic.com             │
   │        Twitter : https://twitter.com/AppsAttic     │
   │         GitLab : https://gitlab.com/appsattic      │
   │                                                    │
   │   Node.js / npm                                    │
   │   -------------                                    │
   │                                                    │
   │        Profile : https://www.npmjs.com/~chilts     │
   │           Card : $ npx chilts                      │
   │                                                    │
   ╘════════════════════════════════════════════════════╛

(Ends)

Package Sidebar

Install

npm i @reacthooks.org/use-local-storage

Weekly Downloads

0

Version

1.0.7

License

ISC

Unpacked Size

7.59 kB

Total Files

5

Last publish

Collaborators

  • chilts
  • chilts-appsattic