Skip to content

[@types/react] useEffect with Promise #30455

@xiaoxiangmoe

Description

@xiaoxiangmoe

If you know how to fix the issue, make a pull request instead.

If you do not mention the authors the issue will be ignored.

now:

    type EffectCallback = () => (void | (() => void));

Can we change it to:

    type EffectCallback = () => (void | (() => void) | Promise<void> | Promise<()=>void>);

This will help to write a callback in the form of an async function.

useEffect(async ()=>{
    const response = await fetchSomeThing('/foo/bar')
    setState(response.data.results);
  }, []);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions