All Projects → dance2die → React Use Localstorage

dance2die / React Use Localstorage

Licence: mit
(seeking maintainers) ⚓ React hook for using local storage

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to React Use Localstorage

Packagephobia
⚖️ Find the cost of adding a new dependency to your project
Stars: ✭ 1,110 (+809.84%)
Mutual labels:  npm, npm-package
Webcam Easy
javascript access webcam stream and take photo
Stars: ✭ 79 (-35.25%)
Mutual labels:  npm, npm-package
Package.json
文件 package.json 的说明文档。
Stars: ✭ 67 (-45.08%)
Mutual labels:  npm, npm-package
Getme
CLI utility for everyday tasks. With getme you get weather, forecast, currency rate, upload files, IP address, word definitions, text translations, internet speed, do google searches, get inspirational quotes and get Chuck Norris jokes
Stars: ✭ 118 (-3.28%)
Mutual labels:  npm, npm-package
Vue Csv Import
Vue.js component to select a CSV file, map the columns to fields, and post it somewhere.
Stars: ✭ 95 (-22.13%)
Mutual labels:  npm, npm-package
React Use Api
Async HTTP request data for axios. Designed for diverse UI states, SSR and data pre-caching.
Stars: ✭ 49 (-59.84%)
Mutual labels:  npm, npm-package
Minimal Feedback
🗳 minimal-feedback is a blazingly fast and highly customizable component to get user feedback.
Stars: ✭ 78 (-36.07%)
Mutual labels:  npm, npm-package
Eslint Plugin Node
Additional ESLint's rules for Node.js
Stars: ✭ 740 (+506.56%)
Mutual labels:  npm, npm-package
Angular File Uploader
Angular file uploader is an Angular 2/4/5/6/7/8/9/10 + file uploader module with Real-Time Progress Bar, Responsive design, Angular Universal Compatibility, localization and multiple themes which includes Drag and Drop and much more.
Stars: ✭ 92 (-24.59%)
Mutual labels:  npm, npm-package
Event Target Shim
An implementation of WHATWG EventTarget interface, plus few extensions.
Stars: ✭ 89 (-27.05%)
Mutual labels:  npm, npm-package
Nls
Missing inspector for npm packages.
Stars: ✭ 44 (-63.93%)
Mutual labels:  npm, npm-package
Node Sonic Channel
🦉 Sonic Channel integration for Node. Used in pair with Sonic, the fast, lightweight and schema-less search backend.
Stars: ✭ 101 (-17.21%)
Mutual labels:  npm, npm-package
Actions Package Update
keeps npm dependencies up-to-date by making pull requests from GitHub Actions or CI.
Stars: ✭ 36 (-70.49%)
Mutual labels:  npm, npm-package
Awesome Node Utils
some useful npm packages for nodejs itself
Stars: ✭ 51 (-58.2%)
Mutual labels:  npm, npm-package
Yarpm
CLI tool to run npm scripts with either npm or yarn, depending on how it was started
Stars: ✭ 13 (-89.34%)
Mutual labels:  npm, npm-package
Incompose
A inferno utility belt for function components and higher-order components
Stars: ✭ 76 (-37.7%)
Mutual labels:  npm, npm-package
Rando.js
The world's easiest, most powerful random function.
Stars: ✭ 659 (+440.16%)
Mutual labels:  npm, npm-package
Np
A better `npm publish`
Stars: ✭ 6,401 (+5146.72%)
Mutual labels:  npm, npm-package
Node Fast Ratelimit
☔️ Fast and efficient in-memory rate-limit for Node, used to alleviate most common DOS attacks.
Stars: ✭ 84 (-31.15%)
Mutual labels:  npm, npm-package
Tplink Cloud Api
A node.js npm module to remotely control TP-Link smartplugs (HS100, HS110) and smartbulbs (LB100, LB110, LB120, LB130) using their cloud web service (no need to be on the same wifi/lan)
Stars: ✭ 96 (-21.31%)
Mutual labels:  npm, npm-package

react-use-localstorage

All Contributors

depends on stable v16.8.1~

version size minzippedsize

Access Local Storage using React hooks.

Fork it on CodeSandbox
Edit usestate-useeffect

How to use it

import React from 'react';
import ReactDOM from 'react-dom';
import useLocalStorage from 'react-use-localstorage';

import './styles.css';

function App() {
  const [item, setItem] = useLocalStorage('name', 'Initial Value');

  return (
    <div className="App">
      <h1>Set Name to store in Local Storage</h1>
      <div>
        <label>
          Name:{' '}
          <input
            type="text"
            placeholder="Enter your name"
            value={item}
            onChange={(e) => setItem(e.target.value)}
          />
        </label>
      </div>
    </div>
  );
}

const rootElement = document.getElementById('root');
ReactDOM.render(<App />, rootElement);

Note for SSR (server-side rendering)

If you are using Gatsby or other SSR frameworks, such as Next.js, refer to this workaround by @hencatsmith.

You need to make sure that window is available.

const useSsrLocalStorage = (
  key: string,
  initial: string
): [string, React.Dispatch<string>] => {
  return typeof window === 'undefined'
    ? [initial, (value: string) => undefined]
    : useLocalStorage(key, initial);
};

Demo

demo

Changelog

Expand Changelog

3.4.0

This version "Watch changes on storage and change state".
Reference: https://github.com/dance2die/react-use-localstorage/pull/30

Thank you @VitorLuizC for the PR and @Svish for the review.

3.3.0

Reverted the implementation of setValue to set localStorage value directly, instead of depending on useEffect.
Reference: window.localstorage updated after value managed by useLocalStorage #29

3.2.1

The library is covered by test. Thank you so much, @SeanMcP~

3.0.0

Decided to go with @TheAifam5 the following breaking change as the type is derived from React type definition.

  • Breadking change: setIteme type is changed from (item: string) => void () to React.Dispatch<string>

  • Updated infrastructure by @TheAifam5 🙏 in PR #13

    • Dropped babel in favor of tsc + uglifyjs

    • Replaced npm with yarn

    • Added husky for pre-commit git hooks

    • Source map has been dropped from distribution

    • distribution is moved from dist to lib folder

      2.4.1

  • Added useLocalStorage return type explicitly to generate correct index.d.ts typing file.

    2.4.0

  • Added TypeScript typings as suggested by @TheAifam5 in Issue #9

    2.3.0

  • Fixed a bug where initial value is returned all the time #7 by @lilasquared 🙏

    2.2.0

  • Sets initial value in local storage

    2.1.0

  • Can optionally pass an initial value

  • This is to prevent form field from being uncontrolled.

    2.0.0

  • Breaking change - setItem doesn't require key

    1.1.1

  • Updated to React v16.8.1, which contains the patched Hooks

    1.1.0

  • Updated dev dependency version

    1.0.0

  • Updated to React v16.8.0, which contains the stable Hooks

    0.0.6

  • Changed the language from JavaScript to TypeScript

  • It has minimized the distribution file greatly

Contributors

Thanks goes to these wonderful people (emoji key):


Aaron Roberts

🤔 🐛 💻

Sung Kim

💻 🐛 📖

TheAifam5

🤔 💻 🚇

Vitor Luiz Cavalcanti

💻

Sean McPherson

⚠️ 💻

Torleif Berger

👀

Evgeny Markov

🐛 🤔

This project follows the all-contributors specification. Contributions of any kind welcome!

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].