react-use-sessionstorage
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

react-use-sessionstorage

Fork of https://github.com/dance2die/react-use-localstorage but then uses session storage instead of local storage.

How to use it

import React from 'react';
import ReactDOM from 'react-dom';
import useSessionStorage from 'react-use-sessionstorage';
 
import './styles.css';
 
function App() {
  const [item, setItem] = useSessionStorage('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);

Package Sidebar

Install

npm i react-use-sessionstorage

Weekly Downloads

291

Version

1.0.2

License

MIT

Unpacked Size

5.04 kB

Total Files

5

Last publish

Collaborators

  • edewit