dev.to | 📄 原文链接 | 2026-08-04 收录

React 19 的 useActionState:禁用提交按钮从来不是防重复提交的正解

来源:dev.to — 2026-07-28

📋 概述

作者回顾了多年来手写表单提交状态(result/submitting/error 三件套加 try/catch/finally)的老模式,以及用本地 isPending 标志“修复”双击提交的隐患——在慢速网络下,那个本地标志可能在实际请求完成前就翻回 false,用户连点三次订单都会各发一次。useActionState 把 isPending 绑定到 React 自己的 transition 跟踪上,而非你猜测时机的布尔值,并自带状态管理与错误处理,从根上解决重复提交问题。

🔑 核心要点

💡 金句

It felt like React quietly admitting they had watched enough of us get this wrong and finally built the fix.
← 返回 Dev.to 首页