All Projects → monojack → react-immer

monojack / react-immer

Licence: MIT license
No nonsense state management with Immer and React hooks

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to react-immer

Easy Peasy
Vegetarian friendly state for React
Stars: ✭ 4,525 (+34707.69%)
Mutual labels:  state-management, immer, react-hooks
east-store
east-store is a state manager with easiest api that based hooks and immer.
Stars: ✭ 18 (+38.46%)
Mutual labels:  state-management, immer, react-hooks
atomic-state
A decentralized state management library for React
Stars: ✭ 54 (+315.38%)
Mutual labels:  state-management, react-hooks
use-simple-store
🏬 Simple state management using React Hook
Stars: ✭ 21 (+61.54%)
Mutual labels:  state-management, react-hooks
Constate
React Context + State
Stars: ✭ 3,519 (+26969.23%)
Mutual labels:  state-management, react-hooks
use-query-string
🆙 A React hook that serializes state into the URL query string
Stars: ✭ 50 (+284.62%)
Mutual labels:  state-management, react-hooks
jedisdb
redis like key-value state management solution for React
Stars: ✭ 13 (+0%)
Mutual labels:  state-management, react-hooks
react-store
A library for better state management in react hooks world
Stars: ✭ 34 (+161.54%)
Mutual labels:  state-management, react-hooks
Use Url State
Lift a React component's state into the url
Stars: ✭ 154 (+1084.62%)
Mutual labels:  state-management, render-props
react-immer-hooks
Easy immutability in React Hooks with Immer.
Stars: ✭ 45 (+246.15%)
Mutual labels:  immer, react-hooks
rematch
The Redux Framework
Stars: ✭ 8,340 (+64053.85%)
Mutual labels:  state-management, immer
concave
🧐 Lens-like state management (for React).
Stars: ✭ 13 (+0%)
Mutual labels:  state-management, react-hooks
use-app-state
🌏 useAppState() hook. that global version of setState() built on Context.
Stars: ✭ 65 (+400%)
Mutual labels:  state-management, react-hooks
hookstore
Hook based and lightweight centralized state management for React.
Stars: ✭ 28 (+115.38%)
Mutual labels:  state-management, react-hooks
react-evoke
Straightforward action-driven state management for straightforward apps built with Suspense
Stars: ✭ 15 (+15.38%)
Mutual labels:  state-management, immer
resynced
An experimental hook that lets you have multiple components using multiple synced states using no context provider
Stars: ✭ 19 (+46.15%)
Mutual labels:  state-management, react-hooks
react-cool-form
😎 📋 React hooks for forms state and validation, less code more performant.
Stars: ✭ 246 (+1792.31%)
Mutual labels:  state-management, react-hooks
nstate
A simple but powerful react state management library with low mind burden
Stars: ✭ 11 (-15.38%)
Mutual labels:  state-management, immer
React Values
A set of tiny React components for handling state with render props.
Stars: ✭ 1,025 (+7784.62%)
Mutual labels:  state-management, render-props
quick-redux
helper functions to make redux and react development quicker
Stars: ✭ 61 (+369.23%)
Mutual labels:  state-management, immer

react-immer

Build Status npm version npm downloads minified size

No nonsense state management with Immer and React hooks

TL;DR

index.js

import React from 'react'
import ReactDOM from 'react'

import { createStore } from 'react-immer'
import Counter from './Counter'

createStore({ count: 1 })

function App() {
  return <Counter />
}

const rootElement = document.getElementById('root')
ReactDOM.render(<App />, rootElement)

 

Counter.js

/* Counter.js */

import React from 'react'
import { useImmer } from 'react-immer'

export default function Counter() {
  const [{ count }, produce] = useImmer({ count: state => state.count })

  const decrement = draft => {
    draft.count -= 1
  }

  const increment = draft => {
    draft.count += 1
  }

  return (
    <div>
      <button onClick={() => produce(decrement)}>-</button>
      <span>{count}</span>
      <button onClick={() => produce(increment)}>+</button>
    </div>
  )
}

Edit react-immer-tldr

What's cool about react-immer is that if you don't support Hooks yet, you can use it inline and it will work like a render prop. In this case, it takes two arguments, the spec object and the render function.

import { useImmer } from 'react-immer'

// ...
// useImmer(specObj, renderFn)
<div>
  {useImmer({ count: state => state.count }, ({ count }, produce) => (
    <span>
      <button onClick={() => produce(decrement)}>-</button>
      <span>{count}</span>
      <button onClick={() => produce(increment)}>+</button>
    </span>
  ))}
</div>

Or, if you don't like the syntax, you can always use the Immer component

import { Immer } from 'react-immer'
// ...

<Immer spec={{ count: state => state.count }}>
  {({ count }, produce) => (
    <span>
      <button onClick={() => produce(decrement)}>-</button>
      <span>{count}</span>
      <button onClick={() => produce(increment)}>+</button>
    </span>
  )}
</Immer>
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].