Skip to main content

use

use is a polyfill hook to resolve promises state for React v18 and below. Note that it only implements the ability to consume promises. For React v19 and above, you can use the built-in use hook: https://react.dev/reference/react/use

Usage

Live Editor
const promise = new Promise((resolve) => {
  setTimeout(() => {
    resolve("resolved");
  }, 5000);
});

function Demo() {
  const data = use(promise);

  return <p>{data}</p>;
};

render(
  <Suspense fallback="loading...">
    <Demo />
  </Suspense>
);

Result

resolved

API

Use

Returns

T: resolved state value

Arguments

ArgumentDescriptionTypeDefaultValue
usablepromise or contextUsable<T> (Required)-

Usable

type Usable<T> = Thenable<T> | Context<T>;
Squarespace
Squarespace makes your marketing, customer management, and checkout flow effortless—all on a single platform.
Get Started