React Immer Hooks
Easy immutability in React Hooks with Immer.
Note: React Hooks are currently a RFC proposal which may be subject to change. You'll need at least react@16.7.0-alpha.0
to use this feature.
Installation
yarn add react-immer-hooks
Usage
useImmerState(initialState)
import useImmerState from 'react-immer-hooks' const initialState = clicks: 0 doubleClicks: 0 const ClickCounters = const state setState = const onClick = const onDoubleClick = return <> <button = => Clics: stateclicks Double clicks: statedoubleClicks </button> </>
useImmerReducer(reducer, initialState)
import useImmerReducer from 'react-immer-hooks' const initialState = count: 0 const reducer = draft action if actiontype === 'INCREMENT' draftcount++ if actiontype === 'DECREMENT' draftcount-- if actiontype === 'ADD' draftcount += actionpayload const Counter = const state dispatch = return <> Count: statecount <button => Increment </button> <button => Decrement </button> <button => Add 5 </button> </>
License
MIT License