Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Simple React hook for localstorage access

License

NotificationsYou must be signed in to change notification settings

bdbch/react-localstorage

Repository files navigation

React hooks for easy and simple localstorage access

You'll need to installreact,react-dom, etc at^16.8.4

Install

npm i @d2k/react-localstorage --save

Usage

React Localstorage gives you simple hooks to work with your localstorage. Here is some example code:

importReactfrom'react'importuseLocalStoragefrom'@d2k/react-localstorage'constApp=()=>{const[firstName,setFirstName,removeFirstName]=useLocalStorage('firstName','John')const[lastName,setLastName,removeLastName]=useLocalStorage('lastName','Doe')// You can update localStorage data via setFirstName('John') or removeFirstName()return(<h1>Demo</h1>{firstName&&lastName&&(<p>        Hello{firstName}{lastName}</p>)})}

Use.set or.remove to update data from your component.

All storage updates will be automatically synced with all components using the same localStorage value key.

About

Simple React hook for localstorage access

Resources

License

Stars

Watchers

Forks

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp