Question: Guidance for async effects?
See original GitHub issueOur team is currently using redux-loop
for handling asynchronous side-effects kicked off by our reducer. We’re really excited about use-methods
, and we’re trying to figure out if there’s any guidance on how to initiate async calls and have those trigger state updates when they complete.
cc @alexburner
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Async/Await - Best Practices in Asynchronous Programming
The guidelines are summarized in Figure 1; I'll discuss each in the following sections. Figure 1 Summary of Asynchronous Programming Guidelines ...
Read more >AspNetCoreDiagnosticScenarios/AsyncGuidance.md at master
This repository has examples of broken patterns in ASP.NET Core applications - AspNetCoreDiagnosticScenarios/AsyncGuidance.md at master ...
Read more >Async Code in useEffect is Dangerous. How Do We Deal with It?
However, we have not considered that the asynchronous workflow in the first useEffect is running concurrently to the rest of the application, ...
Read more >Understanding the Event Loop, Callbacks, Promises, and ...
An async function can handle a promise called within it using the await operator. await can be used within an async function and...
Read more >How to embrace asynchronous communication for remote work
Here is a complete guide to everything you need to know about how to work and communicate asynchronously in a remote work environment....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hey @TedDriggs, if all you’re doing is initiating a single fetch on component mount, this is straightforward to do with just
useEffect
:If you might want to fetch multiple times in the course of the life of the component it gets more complicated, and you probably want to do things like debouncing. There are a lot of interesting hook-based solutions emerging for managing async flows; it’s very early for this space and I think it’s an open question what the right direction is, or whether there will ever be a one-size-fits-all answer to the problem. I’d recommend browsing through here: https://nikgraf.github.io/react-hooks/
useMethods
is really only concerned with solving one problem well, which is managing synchronous state. Whatever async solutions you arrive at,useMethods
should work well with them 😄useMethods is very pluggable. Async effects can be modeled like normal methods. In my implementation I use a wrapper to create async methods: