Skip to content
This repository has been archived by the owner on May 12, 2023. It is now read-only.

andornaut/statezero-react-hooks

Repository files navigation

statezero-react-hooks

React hooks for statezero.

Getting Started

Install from npm.

# Install peer dependencies
npm install react --save
npm install statezero --save

npm install statezero-react-hooks --save

ES6 Module

import { useStatezero } from 'statezero-react-hooks';

ES6 Module with tree shaking (not transpiled)

// Note that the import path ends with '/src'
import { useStatezero } from 'statezero-react-hooks/src';

Usage

Provides the following functions:

import { useStatezero, useStatezeroPath, useStatezeroPathSync, useStatezeroSync } from 'statezero-react-hooks';

let state, setState;
state = useStatezero(selector);
state = useStatezeroSync(selector);
[state, setState] = useStatezeroPath(path);
[state, setState] = useStatezeroPathSync(path);

Example React components

import { useStatezero, useStatezeroPath } from 'statezero-react-hooks/src';

export const component = ({ selector }) => {
  const state = useStatezero(selector);
  // ...
}

export const component = () => {
  const [z, setZ] = useStatezeroPath('x.y.z');
}