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.
-
createContextlets you define and provide context to the child components. Used withuseContext. -
forwardReflets your component expose a DOM node as a ref to the parent. Used withuseRef. -
lazylets you defer loading a component’s code until it’s rendered for the first time. -
memolets your component skip re-renders with same props. Used withuseMemoanduseCallback. -
startTransitionlets you mark a state update as non-urgent. Similar touseTransition. -
actlets you wrap renders and interactions in tests to ensure updates have processed before making assertions.
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.
To read a value from a resource, use this API:
function MessageComponent({ messagePromise }) {
const message = use(messagePromise);
const theme = use(ThemeContext);
// ...
}
© 2013–present Facebook Inc.
Licensed under the Creative Commons Attribution 4.0 International Public License.
https://react.dev/reference/react/apis