内置 React DOM 钩子

react-dom 包包含的 Hook 仅支持用于 Web 应用(在浏览器 DOM 环境中运行)。这些 Hook 在非浏览器环境(如 iOS、Android 或 Windows 应用)中不受支持。如果你正在寻找在 Web 浏览器 及其他环境 中受支持的 Hook,请参见 React Hooks 页面。此页面列出了 react-dom 包中的所有 Hook。

🌐 The react-dom package contains Hooks that are only supported for web applications (which run in the browser DOM environment). These Hooks are not supported in non-browser environments like iOS, Android, or Windows applications. If you are looking for Hooks that are supported in web browsers and other environments see the React Hooks page. This page lists all the Hooks in the react-dom package.


表单钩子

🌐 Form Hooks

表单 让你创建用于提交信息的交互控件。要在组件中管理表单,请使用以下其中一个 Hook:

  • useFormStatus 允许你根据表单的状态更新用户界面。
function Form({ action }) {
async function increment(n) {
return n + 1;
}
const [count, incrementFormAction] = useActionState(increment, 0);
return (
<form action={action}>
<button formAction={incrementFormAction}>Count: {count}</button>
<Button />
</form>
);
}

function Button() {
const { pending } = useFormStatus();
return (
<button disabled={pending} type="submit">
Submit
</button>
);
}