React Reference
Every React 19 hook, component, API and DOM feature in one place: concise, accurate pages with live examples that run in your browser, with signatures, rules and common mistakes.
State Hooks
-
useStateAdd a state variable to a component. -
useState updater functionsCompute the next state from the previous one. -
useState lazy initializationRun expensive initial state code only once. -
useReducerManage complex state with a reducer function. -
useReducer init functionLazily build the initial reducer state. -
useContextRead a value from the nearest context provider. -
useSyncExternalStoreSubscribe to an external store safely. -
useDebugValueLabel a custom hook in React DevTools. -
useIdGenerate stable unique IDs for accessibility attributes.
Effect and Ref Hooks
-
useEffectSynchronize a component with an external system. -
useEffect cleanupUndo what an effect did before it re-runs. -
useEffect dependency arrayControl when an effect re-runs. -
useLayoutEffectRun code before the browser paints. -
useInsertionEffectInject styles before layout effects (for CSS-in-JS libraries). -
useEffectEventRead the latest props and state inside effects without re-running them. -
useRefHold a mutable value that survives renders. -
useRef with DOM nodesAccess and focus DOM elements. -
useImperativeHandleCustomize the handle a parent gets from a ref.
Performance and Concurrency Hooks
-
useMemoCache the result of a calculation between renders. -
useCallbackCache a function definition between renders. -
useTransitionUpdate state without blocking the UI. -
useDeferredValueDefer updating a part of the UI. -
useDeferredValue initial valueShow a placeholder value on the first render. -
useOptimisticShow an optimistic state while an action runs. -
useActionStateUpdate state based on the result of a form action. -
useFormStatusRead the status of the parent form submission. -
useRead a promise or context during render. -
use with SuspenseUnwrap promises and let Suspense show fallbacks.
Components and Special Elements
-
<Fragment>Group elements without a wrapper node. -
Keyed fragmentsGive a fragment a key inside a list. -
<Suspense>Show a fallback while children load. -
Nested Suspense boundariesReveal content in stages. -
<StrictMode>Find bugs early with extra checks in development. -
<Profiler>Measure rendering performance programmatically. -
<Activity>Hide and restore parts of the UI while preserving state. -
<ViewTransition>Animate navigations and updates with view transitions. -
Error boundary classesCatch render errors with getDerivedStateFromError. -
ComponentBase class for class components. -
PureComponentClass component with shallow prop comparison. -
Function componentsDefine components as plain functions. -
Class lifecycle methodscomponentDidMount, componentDidUpdate and friends. -
this.state and setStateState in class components.
Top-Level React APIs
-
createContextCreate a context that components can provide and read. -
Context.Provider and <Context>Provide a context value to a subtree. -
memoSkip re-rendering when props are unchanged. -
lazyDefer loading component code until first render. -
forwardRefPass a ref through a component (legacy in React 19). -
ref as a propReceive refs as a normal prop in React 19. -
startTransitionMark updates as non-urgent without a hook. -
cacheCache the result of a data fetch or computation. -
createElementCreate a React element without JSX. -
cloneElementCreate a copy of an element with new props. -
isValidElementCheck whether a value is a React element. -
ChildrenCount, map and convert the children prop. -
createRefCreate a ref object for class components. -
actWrap updates in tests so they are flushed. -
React.versionThe installed React version string. -
taintObjectReference and taintUniqueValueKeep secrets out of Client Components. -
"use server"Mark server functions callable from the client. -
"use client"Mark the client boundary of a module graph.
react-dom Client APIs
-
createRootCreate a root to render React into a DOM node. -
root.renderRender or update the tree in a root. -
root.unmountDestroy a rendered tree. -
createRoot optionsonUncaughtError, onCaughtError, onRecoverableError. -
hydrateRootAttach React to server-rendered HTML. -
Hydration mismatch errorsWhy server and client HTML differ. -
createPortalRender children into a different DOM node. -
flushSyncForce React to flush updates synchronously. -
findDOMNode (removed)Legacy API and its modern replacement. -
ReactDOM.render (removed)The old root API and how to migrate. -
Automatic batchingHow React groups state updates. -
ReactDOM.versionThe installed react-dom version string.
react-dom Resource and Form APIs
-
preloadFetch a resource early. -
preinitFetch and evaluate a stylesheet or script early. -
preconnectOpen a connection to a server early. -
prefetchDNSResolve a domain name early. -
preloadModuleFetch an ES module early. -
preinitModuleFetch and evaluate an ES module early. -
requestFormResetReset an uncontrolled form after an action. -
<form action>Pass a function to a form as its action. -
FormData in actionsRead submitted fields inside an action. -
useFormStatus in formsDisable buttons while a form submits. -
Hoisted title, meta and linkRender document metadata anywhere in a component. -
Stylesheet precedenceOrder and dedupe stylesheet link elements. -
Async scriptsDeduplicate async script elements across components.
react-dom/server and Static APIs
-
renderToStringRender a tree to an HTML string. -
renderToStaticMarkupRender non-interactive HTML. -
renderToPipeableStreamStream HTML to a Node.js stream. -
renderToReadableStreamStream HTML to a web ReadableStream. -
resume and resumeToPipeableStreamResume a prerendered tree on the server. -
prerenderRender to static HTML and wait for all data. -
prerenderToNodeStreamPrerender to a Node.js stream. -
Streaming with SuspenseSend HTML in chunks as data arrives. -
Bootstrap scripts and optionsbootstrapScripts, nonce and identifierPrefix.
Built-in DOM Components
-
<div> and <span>Generic containers in JSX. -
<input>Controlled and uncontrolled inputs. -
<input type="checkbox">The checked prop and onChange. -
<input type="file">File inputs are always uncontrolled. -
<textarea>Use value instead of children. -
<select>Value, multiple and options. -
<option>Choices inside a select. -
<form>Actions, submit handling and reset. -
<button>Buttons, types and formAction. -
<a>Links and navigation attributes. -
<img>Images, srcSet and loading. -
<progress>Determinate progress with a value. -
<link>Stylesheets and metadata with precedence. -
<meta>Document metadata from components. -
<title>Set the document title from any component. -
<script>Async scripts in React. -
<style>Inline style elements with precedence and href. -
SVG elementsInline SVG with camelCase attributes. -
Custom elementsWeb components and the properties React sets. -
<dialog>Open and close dialogs from React. -
<details>Disclosure widgets and the toggle event. -
<video> and <audio>Media elements and media events. -
TablesTable markup and common JSX errors.
Props and Attributes
-
classNameThe CSS class attribute. -
styleInline styles as an object. -
htmlForConnect a label to a form control. -
keyIdentify items in lists and reset state. -
refGet a reference to a DOM node or component. -
Ref callback functionsRun code when a ref attaches or detaches. -
childrenContent nested between tags. -
dangerouslySetInnerHTMLInsert raw HTML and its risks. -
value and defaultValueControlled versus uncontrolled values. -
checked and defaultCheckedControlled versus uncontrolled checkboxes. -
suppressHydrationWarningSilence expected hydration differences. -
contentEditableEditable elements and warnings. -
aria-* attributesAccessibility attributes keep their hyphens. -
data-* attributesCustom data attributes. -
tabIndexKeyboard focus order. -
Event handler propsonClick, onChange and the camelCase naming. -
SyntheticEventThe event object passed to handlers. -
Capture phase handlersonClickCapture and friends. -
stopPropagation and preventDefaultControl bubbling and default actions. -
onChangeFires on every input change in React. -
onSubmitHandle form submission. -
onScroll and onWheelScroll and wheel events. -
Pointer eventsonPointerDown, onPointerMove, onPointerUp. -
Focus eventsonFocus and onBlur with bubbling. -
Keyboard eventsonKeyDown, key and code. -
Drag eventsonDragStart, onDrop and dataTransfer. -
Clipboard eventsonCopy, onCut and onPaste. -
Animation and transition eventsonAnimationEnd, onTransitionEnd. -
popover attributespopover, popoverTarget and toggle events. -
inertMake a subtree non-interactive.
JSX Syntax and Rules
-
JSX elementsTags that compile to React elements. -
JSX expressionsEmbed JavaScript with curly braces. -
JSX attributesString, expression and boolean attributes. -
JSX spread attributesPass an object of props with spread syntax. -
JSX childrenStrings, elements, arrays and functions as children. -
Short fragment syntaxThe empty-tag fragment and its limits. -
Conditional rendering&&, ternary and early return. -
Rendering listsmap() with keys. -
Comments in JSXWrite comments inside markup. -
JSX whitespaceHow lines and spaces are trimmed. -
Escaping in JSXText is escaped automatically. -
Member tags and casingFoo.Bar tags and lowercase versus uppercase. -
Self-closing tagsEvery tag must be closed. -
The JSX transformjsx() and jsxs() versus createElement. -
JSX with TypeScriptTyping props and elements.
Rules of React
-
Components must be pureSame input, same output. -
Rules of HooksCall hooks only at the top level of components and hooks. -
Never mutate props or stateTreat values as immutable. -
Where side effects belongEvent handlers and effects, not render. -
Immutability of hook valuesDo not mutate values returned from hooks. -
Never call components directlyLet React call your components. -
eslint-plugin-react-hooksLint the rules automatically. -
React CompilerAutomatic memoization and its requirements.
Concepts and Pitfalls
-
Render and commitThe two phases of an update. -
ReconciliationHow React diffs element trees. -
State batchingWhy updates apply after the handler finishes. -
State as a snapshotWhy state does not change mid-render. -
Stale closuresWhy handlers see old values. -
Controlled vs uncontrolledTwo ways to manage form values. -
Lifting state upShare state between components. -
Derived stateCompute values instead of storing them. -
Effects vs event handlersChoosing where code belongs. -
You might not need an effectCommon cases to avoid effects. -
Race conditions in effectsIgnore stale fetch results. -
Infinite render loopsCauses and fixes. -
Resetting state with keysForce a fresh component instance. -
Concurrent renderingInterruptible rendering and transitions. -
How Suspense worksThrowing promises and fallbacks. -
Server ComponentsComponents that run only on the server. -
Server FunctionsCalling the server from the client. -
HydrationMaking server HTML interactive. -
Context performanceAvoid re-render storms. -
Memoization guideWhen memo, useMemo and useCallback help. -
Upgrading to React 19Removed APIs and new behavior. -
Migrating class to hooksLifecycle methods as hooks. -
Common React warningsKeys, unknown props and act warnings. -
Hooks cheat sheetWhich hook for which job.
Không có kết quả nào khớp với “”. Hãy thử tìm kiếm trên trang.
Không có kết quả nào khớp với “”. Hãy thử tìm kiếm trên trang.