admin管理员组文章数量:1417691
In my NextJS 13 app, one of my page.tsx files exports a ponent that can almost fully be rendered on the server. The only client interactivity it needs is a button that calls useRouter.pop() when it's clicked.
As far as I know, this means I need to create a new file with the "use client" directive just to export a client ponent that'll consist of just a button element. This seems like a inefficient way of creating a tiny ponent that will only be used in this one place. Is there any way of creating a client ponent within the page.tsx file?
In my NextJS 13 app, one of my page.tsx files exports a ponent that can almost fully be rendered on the server. The only client interactivity it needs is a button that calls useRouter.pop() when it's clicked.
As far as I know, this means I need to create a new file with the "use client" directive just to export a client ponent that'll consist of just a button element. This seems like a inefficient way of creating a tiny ponent that will only be used in this one place. Is there any way of creating a client ponent within the page.tsx file?
Share Improve this question asked Sep 19, 2023 at 20:45 SylithSylith 7097 silver badges18 bronze badges1 Answer
Reset to default 3Unfortunately in Next.js there is no way of creating both a client and server rendering ponent in a single file.
This seems like a inefficient way of creating a tiny ponent that will only be used in this one place.
The benefits of separating your server page.tsx and your tiny client ponent far outweighs the small inconvenience of having an extra file in your repository.
版权声明:本文标题:javascript - Is it possible to create client and server component in the same file in NextJS 13? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745260770a2650347.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论