New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

react-vault

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-vault

ReactVault is backed by localStorage, keeps and shares states between components and is meant to used with pure React

  • 0.0.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

ReactVault will keep and share state between components. It is backed by window.localStorage and is meant to be used with pure React.

To start using ReactVault first import it in your components

import Vault from 'react-vault';

And initialize it with the method load in the component constructor

constructor(props){
  super(props);
  Vault.load(this); //you should pass the context of the component
}

ReactVault may co-exist with component states and optionally receives an initial state as the second parameter of the load method;

constructor(props){
  super(props);

  this.state = {
    foo: 'Some value'
  };

  Vault.load(this,{name: 'John Doe'}); //second parameter is optional
}

The precedence of states are in order of importance:

**ReactVault State** > **Local State** > **Global State**  

Be careful to pick unique names and handle state keys as more specific states will always overwrite more generic states.

Now use ReactVault to set, get, check and clear state data. They will be kept and shared by all components in your application.

Vault.set('name','Firstname Lastname');
Vault.set('age','30');
Vault.get('name'); //returns Firstname Lastname
Vault.has('name'); //returns true
Vault.clear('name'); //Removes the 'name' key
Vault.clear(); //Clear all data in ReactVault and in all component states

Keywords

FAQs

Package last updated on 03 Jan 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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc