← Back to Tutorials Chapter 14

React Reference

This chapter serves as a comprehensive API reference for React 18+. Use it as a quick lookup when you need the exact signature or behavior of a built-in API.

Top-Level React API

These are exported from the react package and available at the top level:

React.createElement

React.createElement(type, props, ...children)
// Creates a React element. JSX compiles to this.
// type: tag name string | React component | React.Fragment
// props: object or null
// children: any number of child nodes

React.createElement("div", { className: "box" }, "Hello");

React.createRef

React.createRef()
// Creates a ref object: { current: null }
// Used in class components. In function components, use useRef instead.

class MyComp extends React.Component {
  inputRef = React.createRef();
  focus = () => this.inputRef.current.focus();
  render() { return <input ref={this.inputRef} />; }
}

React.forwardRef

React.forwardRef((props, ref) => ReactElement)
// Lets parent components pass a ref through to a child DOM element.

const FancyButton = React.forwardRef(({ children }, ref) => (
  <button ref={ref} className="fancy">{children}</button>
));

React.lazy

React.lazy(() => import("./Component"))
// Returns a dynamically loaded component. Must be wrapped in Suspense.

const LazyChart = React.lazy(() => import("./Chart"));

React.memo

React.memo(Component, [areEqual])
// Memoizes a component — only re-renders if props changed (shallow compare).
// Optional areEqual(prevProps, nextProps) for custom comparison.

const PureList = React.memo(({ items }) => (
  <ul>{items.map(i => <li key={i}>{i}</li>)}</ul>
));

React.startTransition

React.startTransition(callback)
// Marks a state update as a transition (non-urgent).
// Urgent updates (input, clicks) are not blocked by transitions.

startTransition(() => {
  setSearchQuery(query);
});

DOM Reference

These are exported from react-dom and interact with the browser DOM.

createRoot

import { createRoot } from "react-dom/client";
const root = createRoot(container);
root.render(<App />);
// Replaces ReactDOM.render in React 18+. Creates a concurrent root.

hydrateRoot

import { hydrateRoot } from "react-dom/client";
hydrateRoot(container, <App />);
// Hydrates server-rendered HTML. Used with frameworks like Next.js.

render (Legacy)

import ReactDOM from "react-dom";
ReactDOM.render(<App />, container);
// Legacy API — use createRoot for new projects.

findDOMNode (Legacy)

ReactDOM.findDOMNode(componentInstance);
// Returns the underlying DOM node. Avoid — use refs instead.

Hooks API Reference

All built-in hooks with their type signatures:

HookSignatureDescription
useStateuseState<S>(initial: S | (() => S)): [S, Dispatch<SetStateAction<S>>]Local state with lazy initializer
useEffectuseEffect(effect: () => (void | (() => void)), deps?: any[]): voidSide effects after paint; cleanup runs on unmount/deps change
useLayoutEffectuseLayoutEffect(effect, deps?): voidSame as useEffect but fires synchronously after DOM mutations
useContextuseContext<T>(ctx: Context<T>): TReads current context value
useReduceruseReducer<S, A>(reducer: (S, A) => S, initial: S, init?: (S) => S): [S, Dispatch<A>]Complex state with reducer pattern
useCallbackuseCallback<T extends Fn>(fn: T, deps: any[]): TMemoizes a function reference
useMemouseMemo<T>(factory: () => T, deps: any[]): TMemoizes a computed value
useRefuseRef<T>(initial: T): MutableRefObject<T>Mutable ref that persists across renders
useImperativeHandleuseImperativeHandle(ref, createHandle, deps?): voidCustomizes ref exposed from forwardRef
useDebugValueuseDebugValue(value, format?): voidLabels custom hooks in React DevTools
useTransitionuseTransition(): [isPending: boolean, startTransition: (callback) => void]Marks state update as non-urgent
useDeferredValueuseDeferredValue<T>(value: T): TReturns a deferred version of a value
useIduseId(): stringGenerates unique IDs for accessibility attributes
useSyncExternalStoreuseSyncExternalStore(subscribe, getSnapshot, getServerSnapshot?): TSubscribe to external non-React stores
React reference sheet

SyntheticEvent Reference

React wraps native events in a SyntheticEvent for cross-browser consistency. Common event types:

function handleEvent(e: SyntheticEvent) {
  e.preventDefault();
  e.stopPropagation();
  console.log(e.type);     // "click"
  console.log(e.target);   // native DOM element
  console.log(e.currentTarget); // element the handler is attached to
  console.log(e.nativeEvent);   // raw native event
}

Common Recipes

This reference covers React 18 stable APIs. For experimental APIs, refer to the official RFCs and the React documentation at react.dev/reference/react.

Exercise: Build a Recipe Book Portal

  1. Use createPortal to render a details panel overlay.
  2. Implement forwardRef on an Input component so parents can call focus().
  3. Create an ErrorBoundary class component to catch rendering errors.
  4. Use React.memo and useCallback to optimize a list of recipe cards.
  5. Use useDeferredValue to keep the search input responsive while filtering a large list.