Skip to content

khantwaikyaw/next-persist-state

Repository files navigation

next-persist-state

Localstorage for next js

NPM JavaScript Style Guide

Install

npm install --save next-persist-state

Usage

import React from "react";
import usePersistState from "next-persist-state";

const App = () => {
  /** add unique key so that specific state value can be retrieved */
  const [value, setValue, clearValue] = usePersistState(
    "SAMPLE_KEY",
    "Hello World!"
  );

  return (
    <div>
      <div>{value}</div>
      <div>
        <button onClick={() => setValue("New Value")}>set value</button>
        <button onClick={() => clearValue()}>clear value</button>
      </div>
    </div>
  );
};

export default App;

License

MIT © khantwaikyaw


This hook is created using create-react-hook.

About

react hook for state with localstorage

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published