0.2.0 • Published 5 years ago

react-storage-hoc v0.2.0

Weekly downloads
-
License
MIT
Repository
github
Last release
5 years ago

react-storage-hoc

Local and session storage higher-order component for React.

Installation

Via npm:

npm i --save react-storage-hoc

Via yarn:

yarn add react-storage-hoc

Basic Example

import React from 'react';
import { withLocalStorage } from 'react-storage-hoc';

class App extends React.Component {
  render() {
    const { localStorage } = this.props;
    const count = localStorage.count || 0;
    const incCount = () => (localStorage.count = 1 + count);
    const resetCount = () => delete localStorage.count;

    return (
      <div>
        <p>{count}</p>
        <button onClick={incCount}>inc</button>
        <button onClick={resetCount}>reset</button>
      </div>
    );
  }
}

export default withLocalStorage(App);

Examples

These interactive CodeSandbox examples showcase how to use react-storage-hoc.

0.2.0

5 years ago

0.1.0

5 years ago