Skip to content

frankbolviken/localstorage-hook

Repository files navigation

Welcome to @frankbolviken/localstorage-hook 👋

Version Documentation Maintenance License: MIT

React hook which syncs the state to the browsers localstorage. All references to localstorage handled in a way which makes this hook work in nextjs serverside rendered applications.

Prerequisites

  • node >=10

Install

npm install

Usage

import useLocalStorage from '@frankbolviken/localstorage-hook';

const App = () => {
  const [user, setUser] = useLocalStorage < string > ('username', 'John doe');
  return (
    <div>
      The username is {user}
      <button onClick={() => setUser('Batman')}>Change</button>
    </div>
  );
};

Run tests

npm run test

Author

👤 Frank Bølviken

Show your support

Give a ⭐️ if this project helped you!

📝 License

Copyright © 2022 Frank Bølviken.
This project is MIT licensed.


This README was generated with ❤️ by readme-md-generator

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published