You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The `useAsync` hook allows you to call asynchronous closures and retrieve the output in a painless way, and at the same time reduce the number of unnecessary rerenderings. It follows the convention of the standard react hooks in terms of the second dependency array.
14
+
15
+
Whenever the dependency array is changed, the async operation will be reapplied. However, when an operation is ongoing any subsequent updates will be skipped. The last update that was skipped will be executed once the first operation is completed. Which means that the result should always be eventually consistent with the triggering state. This behavior is most likely what you want when async operation is fetching some data or the like. If you are updating data as a side effect, it would be better to use `useAsyncCallback` instead, since that unsures that all operations will be executed.
Both examples above leads to the same outcome. Use whichever way fits your situation best, either passing data as arguments to `execute` or using the closure to pass the data. `execute` will always use the latest closure even though it is referentially stable.
0 commit comments