Last active
January 28, 2021 13:20
-
-
Save MichaelBelousov/2a9a906b1fdb76bad91ba4729e71e734 to your computer and use it in GitHub Desktop.
even more hooks - use useAsyncInterval
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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