Skip to content

#122 Is it possible to use async/await in plain React? #191

Open
@01abhishekjain

Description

@01abhishekjain

The answer given is:

If you want to use async/await in React, you will need Babel and transform-async-to-generator plugin. React Native ships with Babel and a set of transforms.

But, you can use it in React, like so:

function App() {
  const click = async function () {
    await Promise.resolve(123);
  };
  return (
    <div onClick={click}>lorem ipsum</div>
  );
}

What am I missing?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions