[Bug]: Example given in "Handling return values in forms" section for "use-server" docs fails to compile
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 1/5
- Tempo stimato
- Meno di un'ora
- Idoneità per principianti
- 45/100
- Tipo di issue
- Documentazione
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Ferma
- Stack tecnologico
- javascript, react
- Ambito
- documentation
Direzione di ricerca
Inizia con la sezione collegata “Handling return values in forms” nella pagina use-server e confronta il relativo esempio useActionState con la documentazione collegata di useActionState. Aggiorna l’esempio requestUsername in modo che i suoi argomenti corrispondano alla firma dell’azione documentata, quindi verifica che l’esempio della documentazione venga compilato.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Summary
The following example is given in Handling return values in forms section for "use server" docs, fails to compile.
// requestUsername.js
'use server';
export default async function requestUsername(formData) {
const username = formData.get('username');
// ..
}
// UsernameForm.js
'use client';
import { useActionState } from 'react';
import requestUsername from './requestUsername';
function UsernameForm() {
const [state, action] = useActionState(requestUsername, null, 'n/a');
// ..
}
Page
https://react.dev/reference/rsc/use-server#handling-return-values
Details
It fails to compile because, as per the useActionState docs,
useActionState(action, initialState, permalink?)
the "action" (requestUsername in this case) should have previousState as the first argument,
and formData as the second argument.
However, for the above example, the requestUsername action has formData as the first argument,
rather than previousState. Therefore, it fails to compile.
The following is the correct way mentioned in the useActionState docs:
async function increment(previousState, formData) {
return previousState + 1;
}
function StatefulForm({}) {
const [state, formAction] = useActionState(increment, 0);
// ..
}
I can raise a PR for the fix, if it's okay.
- Lingua principale
- JavaScript
- Stelle
- 11.8k
- Fork
- 7.9k
- Merge medio
- 16h 6m
- PR unite (30g)
- 7
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.
Altre issue di reactjs/react.dev
-
type: documentation
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 82/100
-
bug: unconfirmed
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
-
type: typos
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 90/100
-
bug: unconfirmed
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
Tutte le issue di reactjs/react.dev
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
Seeed-Studio/wiki-documents#5655 · 2 commenti ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
-
Edit: CW+ Apertachannels:edit check:passed
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
-
01 type: bug 30 needs: triage 99 tag: UX Accessibility
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
-
documentation
Difficoltà 2/5 1-3 ore Idoneità per principianti 86/100
quarto-dev/quarto-cli#14915 ·