0.1.1 • Published 2 years ago

@anew/hooks v0.1.1

Weekly downloads
1
License
MIT
Repository
github
Last release
2 years ago

@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>
}
0.1.1

2 years ago

0.1.0

2 years ago