@anew/hooks
TypeScript icon, indicating that this package has built-in type declarations

0.1.1 • Public • Published

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

Dependencies (1)

Dev Dependencies (40)

Package Sidebar

Install

npm i @anew/hooks

Weekly Downloads

1

Version

0.1.1

License

MIT

Unpacked Size

46.8 kB

Total Files

28

Last publish

Collaborators

  • abubakir1997