react-storages

Local/Session storage provided via context, reactively.

Usage no npm install needed!

<script type="module">
  import reactStorages from 'https://cdn.skypack.dev/react-storages';
</script>

README

react-storages

Local/Session storage provided via context, reactively.

NPM JavaScript Style Guide

Install

npm install --save react-storages

Usage

import React from 'react'

import { LocalStorage, withLocalStorage, SessionStorage, withSessionStorage } from 'react-storages'

const App = withLocalStorage()(props => {
  setTimeout(() => {
    // Basically, every 7.5 seconds localStorage will be updated,
    // causing this withLocalStorage consumer to rerender and stuff.

    localStorage.setItem("foo", props.storage.foo + "r");
  }, 7500);

  return (
    <div className="App">
      <h1>LocalStorage</h1>
      <h2>foo: {props.storage.foo}</h2>
    </div>
  );
});

const AppContainer = props => {
  return (
    <LocalStorage.Provider>
      <SessionStorage.Provider>
        <App someProp />
      </SessionStorage.Provider>
    </LocalStorage.Provider>
  );
};

License

MIT © colshacol