[Mistakes]: Server Functions examples use incompatible action signatures
Nessuno ha ancora preso questa issue.
- Lingua principale
- JavaScript
- Stelle
- 11.8k
- Fork
- 7.9k
- Merge medio
- 1g 11h
- PR unite (30g)
- 11
Descrizione
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
namestate, soupdateName(name)always receives''. -
On success,
updateNamereturnsundefined, but the client destructures{error}from its result. -
When passed to
<form action={updateName}>, React callsupdateNamewithFormData, 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.
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia dalla pagina di riferimento di Server Functions all’indirizzo https://react.dev/reference/rsc/server-functions e confronta l’esempio updateName tra “Server Functions with Actions”, l’azione del form diretto e l’utilizzo di useActionState. Il lavoro è completo quando i parametri e il valore restituito di ogni esempio corrispondono al modo in cui React lo invoca, inclusi gli argomenti FormData e dello stato precedente.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- javascript, react
- Ambito
- documentation
- Tipo di issue
- Documentazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Stato di attività
- Tranquilla
- Chiarezza
- Specificata chiaramente
- Idoneità per principianti
- 74/100