Global State for React
Install
npm i venti
Quick Start
Get global state
import React from 'react'import useVenti from 'venti' { const state = // this is needed so your component updates when state changes const author title = state // get an object const year = state // or a property return <div>"{title}" by author year</div>}
Set global state
state
API
useVenti( [state] )
state
{State} (optional) defaults to singleton state if not provided- Returns
state
that has been instrumented to update the component when applicable - See StateEventer for more info
state.get( path, [defaultValue] )
path
{Array|string} The path to getdefaultValue
{*} (optional) The value returned for undefined resolved values- Returns the resolved value
state.set( path, value )
path
{Array|string} The path of the property to setvalue
{*} The value to set
state.unset( path )
path
{Array|string} The path of the property to unset
state.update( path, transformFn, [defaultValue] )
path
{Array|string} The path of the property to settransformFn
{Function} transforms the current value to a new valuedefaultValue
{*} (optional) the default value to pass into the transform function if the existing value at the given path is undefinedstate
Advanced Usage
If you don't want to use Venti's singleton state, you can do this:
import React from 'react'import State useVenti from 'venti' const globalState = const useGlobalState = { const state = const title year = state return <div>title year</div>}
Performance Benchmarks
Color Matrix Benchmark
- Venti: https://will123195.github.io/venti-performance/build/
- Redux: https://will123195.github.io/redux-performance/build/
Examples
Tests
npm test
License
MIT