Skip to content

Instantly share code, notes, and snippets.

@reime005
Last active October 25, 2020 19:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save reime005/85db5f2aaf55dfbe8ed05c1c796af0f7 to your computer and use it in GitHub Desktop.
Save reime005/85db5f2aaf55dfbe8ed05c1c796af0f7 to your computer and use it in GitHub Desktop.
import useAsyncEffect from '@n1ru4l/use-async-effect';
useAsyncEffect(
function* (onCancel, c) {
const controller = new AbortController();
onCancel(() => controller.abort());
const data = yield* c(search(controller));
},
[searchValue],
);
const search = controller => fetch('someURL', { signal: controller.signal }).then(r => r.json());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment