use-immer
MobX
use-immer | MobX | |
---|---|---|
8 | 45 | |
3,731 | 27,211 | |
1.6% | 0.2% | |
3.6 | 8.0 | |
7 months ago | 4 days ago | |
TypeScript | TypeScript | |
MIT License | MIT License |
Stars - the number of stars that a project has on GitHub. Growth - month over month growth in stars.
Activity is a relative number indicating how actively a project is being developed. Recent commits have higher weight than older ones.
For example, an activity of 9.0 indicates that a project is amongst the top 10% of the most actively developed projects that we are tracking.
use-immer
-
A cure for React useState hell?
The use-immer package additionally provides a useImmerReducer ****function that allows you to make state transitions via direct mutation, but under the hood creates an immutable copy using Proxies in JavaScript.
-
Zustand vs Jotai vs Valtio? Which state management library do you prefer created by the same team?
Apply useImmer to the top component state and the dream is complete.
-
Copying the contents of an existing array to a new array
If you want to use mutating code while ensuring that the final update is immutable, I recommend checking out useImmer (and useImmerReducer) - it uses immer to track mutations and do them immutably for you.
-
Handling Objects in React Component State
If you find yourself using multiple objects or in your state, it may be worth it to install a library like immer. Immer provides a proxy object, referred to as a draft, so while your code appears similar to a direct mutation of state, a copy is created under the hood when an update when immer is used.
-
Writing useState for each state variable or writing usestate once and use an object
useImmer is also pretty nice too - useReducer is definitely the way if you only want specific ways to manipulate the object though (and useImmerReducer can make writing the logic for that easier too)
-
How to update state of type object array with setstate hook?
Within the component itself, I used a useImmer hook for the state, as it lets me write mutating code while ensuring that the actual update is immutable - but if you're only holding your array in the useState hook, a shallow clone would work fine. js setItems(items => arrayMove([...items], ...params))
-
Electron Adventures: Episode 54: Notebook state management with useImmer
React is a lot more strict, and for what we need we cannot leave the state in individual components, we need to pull it up to the App component. Making modifications to deeply nested state is a lot of nasty code, fortunately React world has a solution - immer and its hooks version useImmer.
- How to handle Immutability in React? (Immer Library to rescue)
MobX
-
Getting started with TiniJS framework
States can also be organized in some central places (aka. stores). You can use Tini Store (very simple, ~50 lines) or other state management solutions such as MobX, TinyX, ...
-
Episode 24/13: Native Signals, Details on Angular/Wiz, Alan Agius on the Angular CLI
Similarly to Promises/A+, this effort focuses on aligning the JavaScript ecosystem. If this alignment is successful, then a standard could emerge, based on that experience. Several framework authors are collaborating here on a common model which could back their reactivity core. The current draft is based on design input from the authors/maintainers of Angular, Bubble, Ember, FAST, MobX, Preact, Qwik, RxJS, Solid, Starbeam, Svelte, Vue, Wiz, and more…
- 5 Alternatives to Redux for React State Management
-
Redux 101
MobX
-
React State Management in 2024
Mutable-based: leverages proxy to create mutable data sources which can be directly written to or reactively read from. Candidates in this group are MobX and Valtio.
-
Show HN: Cami.js – A No Build, Web Component Based Reactive Framework
Looks good! FWIW I always felt the observable pattern much more intuitive than the redux/reducer style. Something like https://mobx.js.org/
Things get hairy in both, but redux pattern feels so ridiculously ceremonially to effectively manage a huge global state object with a false sense of "purity".
Observables otoh say "fuck it, I'm mutating everything, do what you want with it".
-
State Management Alternatives: Best Tools for React Apps
MobX Documentation
-
React native for Linux app development in 2023
There's also others libraries like https://github.com/mobxjs/mobx which aren't specific to RN but can be used in any JS environment.
-
Is redux and thunks still used or are there other alternatives for it now?
Valtio is like simplified MobX
-
What is React State Management?
Link: https://mobx.js.org
What are some alternatives?
Immer - Create the next immutable state by mutating the current one
zustand - 🐻 Bear necessities for state management in React
RxJS - A reactive programming library for JavaScript
xstate - Actor-based state management & orchestration for complex app logic.
Recoil - Recoil is an experimental state management library for React apps. It provides several capabilities that are difficult to achieve with React alone, while being compatible with the newest features of React.
riverpod - A reactive caching and data-binding framework. Riverpod makes working with asynchronous code a breeze.
valtio - 💊 Valtio makes proxy-state simple for React and Vanilla
Cycle.js - A functional and reactive JavaScript framework for predictable code
get_it - Get It - Simple direct Service Locator that allows to decouple the interface from a concrete implementation and to access the concrete implementation from everywhere in your App. Maintainer: @escamoteur
bloc - A predictable state management library that helps implement the BLoC design pattern