Write Asynchronous Producers in Immer and Why You Shouldn’t

Share this video with your friends

Send Tweet

Sometimes our update logic is asynchronous. In this lesson we will investigate two ways in which we can write asynchronous update logic.

…But, we will also discuss why asynchronous producers should be avoided, and how that can be done by better separating our logic.

This lesson also demonstrates the “createDraft” and “finishDraft” APIs

Vadym Kalinin
~ 5 years ago

afaiu this is more like a sugar to avoid creating async wrapper around product(state, draft => {})?

Michel Weststrateinstructor
~ 5 years ago

Sorry, I don't understand the question :) Could you elaborate?

Vadym Kalinin
~ 5 years ago

I'm impressed how fast you are replying! Sorry, I haven't finished last 20 secs at the time writing the question. But you're actually sharing this point there: Such a library isn't supposed to support async recipes in the core. It's much better practice to have an async parent function, where data is fetched first and then passed to the synchronous version of product function.