[Bug]: Example in "Adding Interactivity" works with vite but not with nextjs
Personne n'a encore pris cette issue.
- Langage dominant
- JavaScript
- Étoiles
- 11.8k
- Forks
- 7.9k
- Merge moyen
- 1 j 11 h
- PR mergées (30 j)
- 11
Description
Summary
Description
The below code example on the page https://react.dev/learn/adding-interactivity is deployed correctly when I build the project using vite. However, when I try to deploy the same code in a nextjs project, I get error "Event handlers cannot be passed to Client Component props."
export default function App() {
return (
<Toolbar
onPlayMovie={() => alert('Playing!')}
onUploadImage={() => alert('Uploading!')}
/>
);
}
function Toolbar({ onPlayMovie, onUploadImage }) {
return (
<div>
<Button onClick={onPlayMovie}>
Play Movie
</Button>
<Button onClick={onUploadImage}>
Upload Image
</Button>
</div>
);
}
function Button({ onClick, children }) {
return (
<button onClick={onClick}>
{children}
</button>
);
}
Please note that I am new to React and am using the articles on this website to learn React. So there could be areas where I may be wrong and I apologize for any inconvenience caused due to my ignorance of certain concepts.
I used NextJS first as it was the recommended framework. Only after the code did not deploy, I tried the same code in a new project but this time I used vite.
The error I see is in the browser as below
Runtime ErrorServer
Event handlers cannot be passed to Client Component props.
<button onClick={function onPlayMovie} children=...>
^^^^^^^^^^^^^^^^^^^^^^
If you need interactivity, consider converting part of this to a Client Component.
src/app/App.js (3:5) @ App
1 | export default fun```
Below is the trace from the command line
⨯ Error: Event handlers cannot be passed to Client Component props.
<button onClick={function onPlayMovie} children=...>
^^^^^^^^^^^^^^^^^^^^^^
If you need interactivity, consider converting part of this to a Client Component.
at stringify (<anonymous>)
at stringify (<anonymous>)
at stringify (<anonymous>) {
digest: '1272121264'
}
⨯ Error: Event handlers cannot be passed to Client Component props.
<button onClick={function onUploadImage} children=...>
^^^^^^^^^^^^^^^^^^^^^^^^
If you need interactivity, consider converting part of this to a Client Component.
at stringify (<anonymous>)
at stringify (<anonymous>)
at stringify (<anonymous>) {
digest: '628795184'
}
GET / 500 in 25260ms
Page
https://react.dev/learn/adding-interactivity
Details
Below are the details of my environment from the package.json
"dependencies": {
"react": "19.1.0",
"react-dom": "19.1.0",
"next": "15.5.5"
}
Guide de contribution
Ouvrir le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Piste de recherche
Commencez par la page Adding Interactivity et reproduisez l’exemple dans une application Next.js 15.5.5, puis comparez-le au résultat avec Vite. Déterminez quelles indications ou quel ajustement de l’exemple la page nécessite pour l’erreur signalée de composant serveur/client ; le travail est terminé lorsque la page définit correctement les attentes et documente une méthode fonctionnelle.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- javascript, nextjs, react
- Domaine
- documentation
- Type d'issue
- Bug
- Difficulté
- 3/5
- Temps estimé
- 1-2 jours
- Activité
- À l'abandon
- Clarté
- Plutôt claire
- Accessibilité débutants
- 35/100