One Cool Trick to Simplify Your Reducers

แชร์
ฝัง
  • เผยแพร่เมื่อ 15 ต.ค. 2024
  • 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.
    Blog post with source code: / one-cool-trick-to-simp...
    Immer on GitHub: github.com/imm...
    Resources for JavaScript developers:
    DevAnywhere - Live, remote 1:1 mentorship subscription: DevAnywhere.io
    EricElliottJS.com - Learn TDD, functional programming, software design principles and JavaScript with online, interactive lessons. ericelliottjs.com
    Composing Software eBook: leanpub.com/co...
    Composing Software paperback: amzn.to/3biid58
    Follow me on Twitter / _ericelliott
    Follow JS_Cheerleader on Twitter: / js_cheerleader
    ---
    Eric Elliott is the author of the books, “Composing Software” and “Programming JavaScript Applications”. As co-founder of EricElliottJS.com and DevAnywhere.io, he teaches developers essential software development skills. He builds and advises development teams for crypto projects, and has contributed to software experiences for Adobe Systems, Zumba Fitness, The Wall Street Journal, ESPN, BBC, and top recording artists including Usher, Frank Ocean, Metallica, and many more.
    He enjoys a remote lifestyle with the most beautiful woman in the world.
    #JavaScript #ReactJS #Redux #Code

ความคิดเห็น • 1

  • @dawid_dahl
    @dawid_dahl 4 ปีที่แล้ว +4

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