GithubHelp home page GithubHelp logo

isabella232 / react-use-localstorage Goto Github PK

View Code? Open in Web Editor NEW

This project forked from fezvrasta/react-use-localstorage

0.0 0.0 0.0 213 KB

⚓ React hook for using local storage

Home Page: https://www.npmjs.com/package/react-use-localstorage

License: MIT License

TypeScript 100.00%

react-use-localstorage's Introduction

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);

Demo

demo

Changelog

Expand Changelog

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
Aaron Roberts

🤔 🐛 💻
Sung Kim
Sung Kim

💻 🐛 📖
TheAifam5
TheAifam5

🤔 💻 🚇

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

react-use-localstorage's People

Contributors

allcontributors[bot] avatar dance2die avatar lilasquared avatar theaifam5 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.