New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

react-hooks-shared-state

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-hooks-shared-state

A global state for React with Hooks API.

latest
Source
npmnpm
Version
0.1.0
Version published
Maintainers
1
Created
Source

react-hooks-shared-state

npm version Coverage Status CircleCI

A global state for React with Hooks API.

Installation

$ npm install react-hooks-shared-state --save

Live demo

https://kelp404.github.io/react-hooks-shared-state

Quick start

const {useSharedState} = require('react-hooks-shared-state');

const Component = () => {
  const [state, setState] = useSharedState(null, {value: 'hello'});
  const onChange = e => {
    setState(Object.assign({}, state, {value: e.target.value}));
  };

  return (
    <input value={state.value} onChange={onChange}/>
  );
};

Syntactic sugar

const {useSharedState} = require('react-hooks-shared-state');
const sharedState = require('react-hooks-shared-state');
sharedState.useState()

useSharedState and sharedState.useState are the same one.

setSharedState(state)

const {setSharedState} = require('react-hooks-shared-state');

Assign a new stateful value.

Parameter state

Type: any
Required: required

useSharedState(path, initialState)

const {useSharedState} = require('react-hooks-shared-state');

Returns a stateful value, and a function to update it.

Parameter path

Type: string
Required: optional
The object path of the state.
When the path is null it will return the state(root).
If you just want to use a part of state in the component, pass the object path.

Parameter initialState

Type: any
Required: optional
The initial state.

Keywords

react

FAQs

Package last updated on 03 May 2019

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