Skip to content

Latest commit

 

History

History
46 lines (33 loc) · 1.03 KB

README.md

File metadata and controls

46 lines (33 loc) · 1.03 KB

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.