One Cool Trick to Simplify Your Reducers

preview_player
Показать описание
Redux is an amazing tool if you take the time to get to know it. One of the things about Redux that commonly trips people up is that reducers must be pure functions.

A pure function is a function which:
Given same arguments, always returns the same result, and
Has no side-effects (e.g., it won't mutate its input arguments).

The problem is that sometimes a reducer needs to make a complicated change to some input state, but you can't just mutate the state argument without causing bugs.
The solution is a handy tool called Immer. In this video, I'll introduce you to Immer and show you how to use it to reduce the complexity of your reducer code. With one or two small reducers, the difference is pretty subtle, but on a large project, it can significantly simplify your application code.

Resources for JavaScript developers:

---

He enjoys a remote lifestyle with the most beautiful woman in the world.

#JavaScript #ReactJS #Redux #Code
Рекомендации по теме
Комментарии
Автор

Immer is cool. I love to use Ramda lenses as well!

dawid_dahl