
Security News
The Hidden Blast Radius of the Axios Compromise
The Axios compromise shows how time-dependent dependency resolution makes exposure harder to detect and contain.
react-await
Advanced tools
A react component for handling promises inside JSX.
Use your favourite node package manager to install react-await together with
it's peer dependency react.
# install via NPM …
$ npm install --save react react-await
# … or yarn
$ yarn add react react-await
Basic example using fetch:
import React from "react";
import {Await, Pending, Rejected, Resolved} from "react-await";
function MyIP() {
const promise = fetch("https://api.ipify.org?format=json").then(r => r.json());
return (
<Await promise={promise}>
<Resolved>{json => <div>My IP: {json.ip}</div>}</Resolved>
<Rejected>{error => <div>{error.message}!</div>}</Rejected>
<Pending><div>Fetching …</div></Pending>
</Await>
);
}
Each of the three components Resolved, Rejected and Pending support a
render function or regular JSX components as children. When using render
functions, the Resolved component will pass the promise's result and the
Rejected component the rejection reason as an argument.
Additionally, there is a Then component which combines the functionallity of
the three separate components. It only accepts a render callback as child, which
will be invoked with the current promise state (pending, resolved or
rejected), an optional result and an optional rejection reason. You should use
Then if your component has inner state and must not be unmounted between
promise state transitions.
The example from above could also be written as the following:
import React from "react";
import {Await, Then, PromiseState} from "react-await";
function MyIP() {
const promise = fetch("https://api.ipify.org?format=json").then(r => r.json());
return (
<Await promise={promise}>
<Then>
{(state, json, error) => {
switch (state) {
case PromiseState.Resolved:
return <div>My IP: {json.ip}</div>;
case PromiseState.Rejected:
return <div>{error.message}!</div>;
case PromiseState.Pending:
default:
return <div>Fetching …</div>;
}
}
</Then>
</Await>
);
}
As react-await uses the new context introduced with react 16.3 internally,
rendering multiple or nested Resolved, Rejected, Pending and Then
components is also supported. Additionaly, the Await component will
automatically cleanup callback functions from old promises when passing a new
promise or unmounting.
Try it on codesandbox.io!
FAQs
A react component for handling promises inside JSX.
We found that react-await demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
The Axios compromise shows how time-dependent dependency resolution makes exposure harder to detect and contain.

Research
A supply chain attack on Axios introduced a malicious dependency, plain-crypto-js@4.2.1, published minutes earlier and absent from the project’s GitHub releases.

Research
Malicious versions of the Telnyx Python SDK on PyPI delivered credential-stealing malware via a multi-stage supply chain attack.