Skip to content

Latest commit

 

History

History
41 lines (30 loc) · 2.16 KB

apis.md

File metadata and controls

41 lines (30 loc) · 2.16 KB
title Built-in React APIs

In addition to Hooks and Components, the react package exports a few other APIs that are useful for defining components. This page lists all the remaining modern React APIs.


  • createContext lets you define and provide context to the child components. Used with useContext.
  • lazy lets you defer loading a component's code until it's rendered for the first time.
  • memo lets your component skip re-renders with same props. Used with useMemo and useCallback.
  • startTransition lets you mark a state update as non-urgent. Similar to useTransition.
  • act lets you wrap renders and interactions in tests to ensure updates have processed before making assertions.
  • cache lets you cache the result of a data fetch or computation.
  • cacheSignal lets you know when the cache() lifetime is over.
  • captureOwnerStack reads the current Owner Stack in development and returns it as a string if available.

Resource APIs {/resource-apis/}

Resources can be accessed by a component without having them as part of their state. For example, a component can read a message from a Promise or read styling information from a context.

You can pass these types of resources to use:

  • A Promise to read its resolved value.
  • A context to read its value.
  • The value returned by browser to mark a component as browser-only during server rendering.
function MessageComponent({ messagePromise }) {
  const message = use(messagePromise);
  const theme = use(ThemeContext);
  use(browser());
  // ...
}