npm.io
1.0.1 • Published 7 years ago

unstated-storage

Licence
MIT
Version
1.0.1
Deps
1
Size
16 kB
Vulns
0
Weekly
0

unstated-storage

package version package downloads standard-readme compliant package license make a pull request

Persist your unstated container in local or session storage

Table of Contents

Install

This project uses node and npm.

$ npm install unstated-storage
$ # OR
$ yarn add unstated-storage

Usage

import { StoredContainer } from 'unstated-storage' 

class Example extends StoredContainer {
    state = {
        count: 0
    }

    store = {
        version: 1, // Check for matching version in storage to populate
                    // If omitted, will just call setState with state at key
        storage: window.sessionStorage,
        key: 'example'
    }

    increment () {
        this.setState(currentState = ({...currentState, count: ++currentState.count}))
    }
}

export default Example

Contribute

  1. Fork it and create your feature branch: git checkout -b my-new-feature
  2. Commit your changes: git commit -am "Add some feature"
  3. Push to the branch: git push origin my-new-feature
  4. Submit a pull request

License

MIT