[Suggestion]: Provide examples for useActionState with onSubmit handlers
まだ誰も着手していません。
- 主要言語
- JavaScript
- スター
- 11.8k
- フォーク
- 7.9k
- 平均マージ
- 1日 11時間
- マージ済み PR(30日)
- 11
説明
Summary
Add examples to the useActionState documentation showcasing how it can work inside onSubmit handlers of forms.
Page
https://react.dev/reference/react/useActionState
Details
The docs show how to use useActionState with the action property of a form. However, the docs don't show how to use useActionState when you need to use it from onSubmit instead. This has been something that I have been fighting.
Let's say you are developing a multi-step / wizard form across multiple components. Not all of the form is rendered at the same time, so uncontrolled components won't work here. You need to use controlled components for your input fields in order to keep all the form state as you go through steps.
When it comes to submission, using action={formAction} won't work anymore, because that will only submit with the input fields currently rendered. It is not at all clear what the expectations are for doing this in the onSubmit handler instead.
When I attempt to do something like this:
<form
onSubmit={form.onSubmit(async (values, event) => {
const formData = new FormData();
for (const [key, value] of Object.entries(values)) {
formData.append(key, value);
}
startTransition(async () => {
await formAction(formData);
});
})}
>
I get interesting messages like TS80007: await has no effect on the type of this expression. on the line calling my form action, and I can't await the result and/or handle it.
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
Issue にリンクされている useActionState リファレンスページから始め、既存の form action の例を確認してください。制御された複数ステップのフォーム向けに、form action を呼び出してその結果を処理する方法を説明する onSubmit の例を追加し、ドキュメント化された動作で報告された await と TypeScript に関する混乱が解消されることを確認してください。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- javascript, react
- 領域
- documentation, frontend
- issue の種類
- ドキュメント
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 55/100