reactjs / reactjs/react.dev

[Mistakes]: Server Functions examples use incompatible action signatures

オープン
#8,537 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

type: typos
主要言語
JavaScript
スター
11.8k
フォーク
7.9k
平均マージ
1日 11時間
マージ済み PR(30日)
11

説明

Summary

The updateName Server Function is defined as updateName(name), but the page later uses it as a direct form action and with useActionState. These usages pass different arguments, so the examples cannot work with the shown function.

Page

https://react.dev/reference/rsc/server-functions

Details

The page defines:

export async function updateName(name) {
  if (!name) {
    return {error: 'Name is required'};
  }
  await db.users.updateName(name);
}

There are several inconsistencies/mistakes:

  • In “Server Functions with Actions”, the input does not update the name state, so updateName(name) always receives ''.

  • On success, updateName returns undefined, but the client destructures {error} from its result.

  • When passed to <form action={updateName}>, React calls updateName with FormData, not a string.

  • When passed to useActionState, React calls it with (previousState, FormData), and it must consistently return the next state.

The examples should define a Server Function with the correct parameters and return value for each usage.

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

https://react.dev/reference/rsc/server-functions の Server Functions リファレンスページから始め、「Server Functions with Actions」、直接のフォームアクション、useActionState の使用における updateName の例を比較します。各例のパラメーターと戻り値が、FormData 引数と前の状態の引数を含め、React がそれを呼び出す方法と一致すれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
javascript, react
領域
documentation
issue の種類
ドキュメント
難易度
3/5
見積もり時間
1〜2日
活発さ
静か
明瞭さ
明確に書かれている
初心者へのやさしさ
74/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。