React API index
Search common React components, hooks, and APIs by name or task.
Search the React APIs introduced across the course, then expand an entry for its purpose and a small example. Examples use JavaScript and assume they are placed inside a component where shown.
This is a focused guide, not a complete API reference. Check the official docs for rules of hooks, version-specific APIs, and details of server or framework environments.
Sources: React reference, React DOM reference, React: Escape Hatches
12 results in 4 categories
Components and composition
Compose UI from built-in React components and reusable functions.
Fragment<Fragment>...</Fragment> | <>...</>Group sibling elements without adding a DOM wrapper.
Use the explicit Fragment form when a list needs a key on the group.
import { Fragment } from "react";
function Names({ people }) {
return people.map((person) => (
<Fragment key={person.id}><h2>{person.name}</h2><hr /></Fragment>
));
}React documentation memomemo(Component, arePropsEqual?)Skip some re-renders when props have not changed.
Treat memo as a performance optimization, not a correctness requirement. Measure before adding it.
import { memo } from "react";
const Greeting = memo(function Greeting({ name }) {
return <h2>Hello, {name}</h2>;
});React documentation lazy / Suspenselazy(load) | <Suspense fallback={...}>Load a component on demand and show fallback UI while it loads.
Define lazy components outside other components and place them beneath a Suspense boundary.
import { lazy, Suspense } from "react";
const Reports = lazy(() => import("./Reports"));
function App() {
return <Suspense fallback={<p>Loading…</p>}><Reports /></Suspense>;
}React documentation Hooks and state
Store component state and share values with React hooks.
useStateuseState(initialState)Add a state variable to a function component.
The setter schedules a render. When the next value depends on the previous one, use the updater form.
import { useState } from "react";
function Counter() {
const [count, setCount] = useState(0);
return <button onClick={() => setCount((value) => value + 1)}>{count}</button>;
}React documentation useReduceruseReducer(reducer, initialState)Manage related state updates with a reducer function.
A reducer receives the current state and an action, then returns the next state.
import { useReducer } from "react";
function reducer(state, action) {
if (action.type === "increment") return { count: state.count + 1 };
return state;
}
const [state, dispatch] = useReducer(reducer, { count: 0 });React documentation createContext / useContextcreateContext(defaultValue) | useContext(Context)Provide and read a value across a component subtree.
Context is useful for values needed by distant components. It does not replace local state or every prop.
import { createContext, useContext } from "react";
const ThemeContext = createContext("light");
function Label() {
const theme = useContext(ThemeContext);
return <span className={theme}>Status</span>;
}React documentation useRefuseRef(initialValue)Keep a mutable value that does not trigger a render when changed.
Commonly used to reference a DOM node or retain a value between renders that is not part of the visible UI.
import { useRef } from "react";
function SearchBox() {
const inputRef = useRef(null);
return <input ref={inputRef} />;
}React documentation Effects and events
Respond to user actions and synchronize with external systems.
useEffectuseEffect(setup, dependencies?)Synchronize a component with an external system.
Use effects for subscriptions, browser APIs, and other external synchronization—not to derive values that can be calculated during render.
import { useEffect } from "react";
useEffect(() => {
const connection = createConnection(serverUrl);
connection.connect();
return () => connection.disconnect();
}, [serverUrl]);React documentation useIduseId()Generate an ID for accessibility relationships.
Useful for matching a label with its input. Do not use it to create list keys.
import { useId } from "react";
function EmailField() {
const id = useId();
return <><label htmlFor={id}>Email</label><input id={id} /></>;
}React documentation startTransition / useTransitionstartTransition(action) | useTransition()Mark non-urgent UI updates as transitions.
Keep urgent interactions such as typing responsive while React works on a lower-priority update.
import { startTransition, useState } from "react";
function TabButton() {
const [tab, setTab] = useState("home");
function selectTab(nextTab) {
startTransition(() => setTab(nextTab));
}
return <button onClick={() => selectTab("reports")}>{tab}</button>;
}React documentation Performance helpers
Cache calculations or callback identities when profiling shows a need.
useMemouseMemo(calculateValue, dependencies)Cache a calculation result between renders.
Use for measured expensive calculations or when a stable value is needed by a memoized child. React Compiler may reduce the need for manual memoization.
import { useMemo } from "react";
const visibleItems = useMemo(
() => filterItems(items, query),
[items, query],
);React documentation useCallbackuseCallback(fn, dependencies)Cache a function definition between renders.
Most useful when passing a callback to an optimized child or using it as a dependency in another hook.
import { useCallback } from "react";
const handleSave = useCallback(() => {
saveDocument(documentId);
}, [documentId]);React documentation Finished the course? Visit the references and further reading.