试了下 useActionState,整体思路很好,但 API 设计有点绕。它要传一个 reducer 风格的函数,返回值是 [state, action, isPending],跟传统 hook 习惯不太一样。
const [state, formAction, pending] = useActionState(submitFn, initialState);
pending 是后加的,之前还得自己包一个 transition 拿 isPending。现在爽多了。
但错误信息的 TS 类型推导有点弱,得手动标 union,不然 state.error 推不出来。
你们用下来感觉咋样?有没有更好的封装姿势?