All Projects → sin → react-immer-hooks

sin / react-immer-hooks

Licence: MIT license
Easy immutability in React Hooks with Immer.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to react-immer-hooks

Easy Peasy
Vegetarian friendly state for React
Stars: ✭ 4,525 (+9955.56%)
Mutual labels:  immer, react-hooks
east-store
east-store is a state manager with easiest api that based hooks and immer.
Stars: ✭ 18 (-60%)
Mutual labels:  immer, react-hooks
React Copy Write
✍️ Immutable state with a mutable API
Stars: ✭ 1,810 (+3922.22%)
Mutual labels:  immer, copy-on-write
react-immer
No nonsense state management with Immer and React hooks
Stars: ✭ 13 (-71.11%)
Mutual labels:  immer, react-hooks
wenaox
🐬 A light weight and good performance micro channel small program state management library
Stars: ✭ 33 (-26.67%)
Mutual labels:  immer
quick-redux
helper functions to make redux and react development quicker
Stars: ✭ 61 (+35.56%)
Mutual labels:  immer
immer-adapter
🐹 Declarative state mutations
Stars: ✭ 47 (+4.44%)
Mutual labels:  immer
btrfs-backup
A simple, flexible script for versioned backups using btrfs and rsync
Stars: ✭ 59 (+31.11%)
Mutual labels:  copy-on-write
use-google-sheets
📝 A React Hook for getting data from Google Sheets API v4
Stars: ✭ 75 (+66.67%)
Mutual labels:  react-hooks
react-hooks-lifecycle
⚛️ 🪝 ⏳ React hooks lifecycle diagram: Functional components lifecycle explained
Stars: ✭ 194 (+331.11%)
Mutual labels:  react-hooks
react-evoke
Straightforward action-driven state management for straightforward apps built with Suspense
Stars: ✭ 15 (-66.67%)
Mutual labels:  immer
ngrx-slice
Moved to https://github.com/nartc/nartc-workspace
Stars: ✭ 50 (+11.11%)
Mutual labels:  immer
nstate
A simple but powerful react state management library with low mind burden
Stars: ✭ 11 (-75.56%)
Mutual labels:  immer
rematch
The Redux Framework
Stars: ✭ 8,340 (+18433.33%)
Mutual labels:  immer
react-7h-hooks
(持续增加中)提供一些偏业务的实用 react hooks, 让你每天只工作 7 小时 !
Stars: ✭ 15 (-66.67%)
Mutual labels:  react-hooks
ngrx-etc
Utility functions for NgRx
Stars: ✭ 70 (+55.56%)
Mutual labels:  immer
immerx-state
Reactive, fractal and no-nonsense state management with Immer
Stars: ✭ 19 (-57.78%)
Mutual labels:  immer
use-route-as-state
Use React Router route and query string as component state
Stars: ✭ 37 (-17.78%)
Mutual labels:  react-hooks
use-axios-react
React axios hooks for CRUD
Stars: ✭ 31 (-31.11%)
Mutual labels:  react-hooks
React Boilerplate
🔥 A highly scalable, offline-first foundation with the best developer experience and a focus on performance and best practices.
Stars: ✭ 28,151 (+62457.78%)
Mutual labels:  immer

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 [email protected] 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 ] = useImmerState(initialState)

  const onClick = () => setState(draft => { draft.clicks++ })
  const onDoubleClick = () => setState(draft => { draft.doubleClicks++ })

  return (
    <>
      <button onClick={onClick} onDoubleClick={onDoubleClick}>
        Clics: {state.clicks}, Double clicks: {state.doubleClicks}
      </button>
    </>
  )
}
useImmerReducer(reducer, initialState)
import { useImmerReducer } from 'react-immer-hooks'

const initialState = {
  count: 0
}

const reducer = (draft, action) => {
  if (action.type === 'INCREMENT') draft.count++
  if (action.type === 'DECREMENT') draft.count--
  if (action.type === 'ADD') draft.count += action.payload
}

const Counter = () => {
  const [ state, dispatch ] = useImmerReducer(reducer, initialState)

  return (
    <>
      Count: {state.count}
      <button onClick={() => dispatch({ type: 'INCREMENT'})}>
        Increment
      </button>
      <button onClick={() => dispatch({ type: 'DECREMENT'})}>
        Decrement
      </button>
      <button onClick={() => dispatch({ type: 'ADD', payload: 5})}>
        Add 5
      </button>
    </>
  )
}

License

MIT License

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].