0.0.1 • Published 6 years ago

react-storages v0.0.1

Weekly downloads
2
License
MIT
Repository
github
Last release
6 years ago

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