-
Notifications
You must be signed in to change notification settings - Fork 50.6k
Closed
Closed
Copy link
Labels
Status: UnconfirmedA potential issue that we haven't yet confirmed as a bugA potential issue that we haven't yet confirmed as a bug
Description
Consider the following code:
useAsyncEffect(async () => {
await foo()
}, []);Eslint give the following error:
11:18 error Effect callbacks are synchronous to prevent race conditions. Put the async function inside:
useEffect(() => {
async function fetchData() {
// You can await here
const response = await MyAPI.getData(someId);
// ...
}
fetchData();
}, [someId]); // Or [] if effect doesn't need props or stateThere are 2 problems with that:
- The error is provided by
react-hooks/exhaustive-deps, but this has nothing to do with deps or exhaustiveness. I can't disable this warning without disable actually checking for exhaustive deps. - In general the error is bogus. Statement "Effect callbacks are synchronous to prevent race conditions" is only true for built-in effects, and is definitely not true for
useAsyncEffect, which built specifically to support asynchronous callbacks.
eslint-plugin-react-hooks version: 4.0.0
The current behavior
react-hooks/exhaustive-deps gives an error for this code
The expected behavior
react-hooks/exhaustive-deps should not give an error for this code
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
Status: UnconfirmedA potential issue that we haven't yet confirmed as a bugA potential issue that we haven't yet confirmed as a bug