Can I use Suspense for server components?
Answered
Nelson posted this in #help-forum
NelsonOP
I am using server actions in the child component.
Can I write something like this? Is it work?
Can I write something like this? Is it work?
const BlogPage = () => {
return (
<Suspense fallback='loading comments...'>
<Comments />
</Suspense>
)
}
export default BlogPageconst Comments = async () => {
const comments = await getComments()
return (
// ...
)
}Answered by joulev
1. yes the Suspense works
2. no, the
2. no, the
getComments is not acting as a server action here, hence don't make it a server action: https://nextjs-forum.com/post/12021862212758610632 Replies
@Nelson I am using server actions in the child component.
Can I write something like this? Is it work?
tsx
const BlogPage = () => {
return (
<Suspense fallback='loading comments...'>
<Comments />
</Suspense>
)
}
export default BlogPage
tsx
const Comments = async () => {
const comments = await getComments()
return (
// ...
)
}
1. yes the Suspense works
2. no, the
2. no, the
getComments is not acting as a server action here, hence don't make it a server action: https://nextjs-forum.com/post/1202186221275861063Answer