@anew/hooks
v0.1.1
Published
AnewJS React Hooks
Downloads
7
Readme
@anew/hooks
AnewJS hooks for react application
Updates
For updates checkout Change Log.
Installation
To install @anew/hooks
directly into your project run:
npm i @anew/hooks -S
for yarn users, run:
yarn add @anew/hooks
Usage
import {createStore} from '@anew/store'
import {createUseStoreState} from '@anew/hooks'
// Example Store
const CounterStore = createStore({ count: 1 })
// Create Hook to use counter state
const useCounterState = createUseStoreState(CounterStore)
// Usage
const Counter = () => {
const count = useCounterState(state => state.count)
// ⚠️ NOTE: Use shallowEqal when returning an object
// Otherwise the a re-render will be triggered on any
// state change since the a new object is instanitated every time
const {count} = useStoreState.withSallowEqual(state => ({ count: state.count }))
return <div>{count}<div>
}