rauldeheer / Use Async Effect
Licence: mit
🏃 Asynchronous side effects, without the nonsense
Stars: ✭ 193
Programming Languages
javascript
184084 projects - #8 most used programming language
Projects that are alternatives of or similar to Use Async Effect
Asyncex
A helper library for async/await.
Stars: ✭ 2,794 (+1347.67%)
Mutual labels: async, async-await, await
P Iteration
Utilities that make array iteration easy when using async/await or Promises
Stars: ✭ 337 (+74.61%)
Mutual labels: async, async-await, await
Coerce Rs
Coerce - an asynchronous (async/await) Actor runtime and cluster framework for Rust
Stars: ✭ 231 (+19.69%)
Mutual labels: async, async-await, await
Await Of
await wrapper for easier errors handling without try-catch
Stars: ✭ 240 (+24.35%)
Mutual labels: async, async-await, await
Swiftcoroutine
Swift coroutines for iOS, macOS and Linux.
Stars: ✭ 690 (+257.51%)
Mutual labels: async, async-await, await
Hooks
Async middleware for JavaScript and TypeScript
Stars: ✭ 117 (-39.38%)
Mutual labels: async, hooks
Cppcoro
A library of C++ coroutine abstractions for the coroutines TS
Stars: ✭ 2,118 (+997.41%)
Mutual labels: async, async-await
Asynquence
Asynchronous flow control (promises, generators, observables, CSP, etc)
Stars: ✭ 1,737 (+800%)
Mutual labels: async, async-await
Swimmer
🏊 Swimmer - An async task pooling and throttling utility for JS
Stars: ✭ 94 (-51.3%)
Mutual labels: async, await
Futures Intrusive
Synchronization primitives for Futures and async/await based on intrusive collections
Stars: ✭ 137 (-29.02%)
Mutual labels: async, async-await
Async Backplane
Simple, Erlang-inspired fault-tolerance framework for Rust Futures.
Stars: ✭ 113 (-41.45%)
Mutual labels: async, async-await
Aiormq
Pure python AMQP 0.9.1 asynchronous client library
Stars: ✭ 112 (-41.97%)
Mutual labels: async, async-await
Nim Chronos
Chronos - An efficient library for asynchronous programming
Stars: ✭ 136 (-29.53%)
Mutual labels: async, async-await
Mobc
A generic connection pool for Rust with async/await support
Stars: ✭ 141 (-26.94%)
Mutual labels: async, await
Hydra
⚡️ Lightweight full-featured Promises, Async & Await Library in Swift
Stars: ✭ 1,954 (+912.44%)
Mutual labels: async, await
Asyncutilities
A collection of somewhat useful utilities and extension methods for async programming
Stars: ✭ 157 (-18.65%)
Mutual labels: async, async-await
🏃 Asynchronous side effects, without the nonsense.
useAsyncEffect(async () => {
await doSomethingAsync();
});
Installation
npm install use-async-effect
or
yarn add use-async-effect
This package ships with TypeScript and Flow types.
API
The API is the same as React's useEffect()
, except for some notable differences:
- The destroy function is passed as an optional second argument:
useAsyncEffect(callback, dependencies?);
useAsyncEffect(callback, onDestroy, dependencies?);
- The async callback will receive a single function to check whether the component is still mounted:
useAsyncEffect(async isMounted => {
const data1 = await fn1();
if (!isMounted()) return;
const data2 = await fn2();
if (!isMounted()) return;
doSomething(data1, data2);
});
Examples
Basic mount/unmount
useAsyncEffect(async () => console.log('mount'), () => console.log('unmount'), []);
Omitting destroy
useAsyncEffect(async () => console.log('mount'), []);
Handle effect result in destroy
useAsyncEffect(() => fetch('url'), (result) => console.log(result));
Making sure it's still mounted before updating component state
useAsyncEffect(async isMounted => {
const data = await fetch(`/users/${id}`).then(res => res.json());
if (!isMounted()) return;
setUser(data);
}, [id]);
Note that the project description data, including the texts, logos, images, and/or trademarks,
for each open source project belongs to its rightful owner.
If you wish to add or remove any projects, please contact us at [email protected].