Skip to content

Parent class for components which should persist their state to localStorage

Notifications You must be signed in to change notification settings

patchkit/patchkit-ls-persisted

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

LocalStoragePersistedComponent

Parent class for components which should persist their state to localStorage.

  • subclasses must call super(props, storageId), where storageId is the localStorage key
  • subclasses should provide defaultState to set which values are persisted, and give initial values

Example - a input-field which persists its value to localstorage:

import LocalStoragePersistedComponent from './index'

class LSPInput extends LocalStoragePersistedComponent {
  constructor(props) {
    super(props, 'persisted-input', { value: '' })
  }
  onChange(e) {
    this.setState({ value: e.target.value })
  }
  render() {
    return <input value={this.state.value} onChange={this.onChange.bind(this)} />
  }
}

<LSPInput />

About

Parent class for components which should persist their state to localStorage

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published