Handling side effects
What is a side effect? A side effect is something that isn't part of the normal code flow but something that accesses outside resources, such as filesystems or resources on other networks. In the context of Redux, side effects are most often used for carrying out AJAX calls. Once that call comes back, we most likely need to update the state of the store because something has changed. How would we implement such a function? One is add a method effect() that would take a function. The said function would take dispatch method as a parameter so that the parameter function can carry out a dispatch, should it have a need for it, once the side effect has run its course. Let's imagine it is being used in the following way:
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access