Skip to content

Instantly share code, notes, and snippets.

@MichaelBelousov
Last active January 28, 2021 13:20
Show Gist options
  • Save MichaelBelousov/2a9a906b1fdb76bad91ba4729e71e734 to your computer and use it in GitHub Desktop.
Save MichaelBelousov/2a9a906b1fdb76bad91ba4729e71e734 to your computer and use it in GitHub Desktop.
even more hooks - use useAsyncInterval
import { useAsyncInterval } from "@bentley/react-hooks";
//...
useAsyncInterval(
async ({isStale, setCancel}) => {
const aborter = new AbortController();
setCancel(() => aborter.abort());
const response = await fetch("http://localhost:3001/tank-params", { signal: aborter.signal });
const result = await response.json();
if (!isStale()) setTankParamValue(result[tankParamType]);
},
1000
).catch((err) => {
if (e.name !== "AbortError") console.error(err)
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment