🚀 Big News:Socket Has Acquired Secure Annex.Learn More →
Socket
Book a DemoSign in
Socket

react-persist

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-persist

Persist and rehydrate React state

latest
Source
npmnpm
Version
1.0.2
Version published
Weekly downloads
2.8K
-3.98%
Maintainers
1
Weekly downloads
 
Created
Source

React Persist đź’ľ

Persist and rehydrate React state to localStorage.

npm install react-persist --save

Basic Usage

Just import the <Persist > component and pass it the data you want it to persist. It renders null, so it can go wherever you need it to....

import React from 'react'
import { Persist } from 'react-persist'

class Signup extends React.Component {
  state = {
   firstName: '',
   lastName: '',
   email: '',
   isLoading: false,
   error: null
  };

  // ...

  render() {
    return (
      <form onSubmit={this.handleSubmit}>
        {/* whatever....*/}
        <Persist 
          name="signup-form" 
          data={this.state} 
          debounce={500} 
          onMount={data => this.setState(data)}
        />
      </form>
    )
  }

Props

Only a few of them!

  • name: string: LocalStorage key to save form state to
  • data: any: Data to persist
  • debounce:? number: Number of ms to debounce the function that saves form state. Default is 300.
  • onMount: (data: any) => void: (optionally) Hydrate your data (into React state). Will only be called if data is not null.

Author

  • Jared Palmer @jaredpalmer

Todo

  • Alternative storages (localForage, sessionStorage)
  • Support AsyncStorage for React Native

Keywords

react

FAQs

Package last updated on 04 Oct 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts