Skip to content

Next.js server component with react-stately Item component #5030

Answered by devongovett
Cuttsy27 asked this question in Q&A
Discussion options

You must be logged in to vote

Collection components like Item must be rendered from a client component, not a server component. You must have "use client" in the file where you render <Item> (or in a file above that).

The reason is that we traverse the JSX tree to find the items, specifically looking for elements with element.type === Item. However, server components / Next.js rewrites these to be React.lazy when they are rendered in a server component. That makes it impossible for us to tell what the actual type of the element is, hence the error you see here.

As Rob mentioned, in the future we'll have a new implementation of collections that works better with server components. However, that's not publicly exported …

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
2 replies
@tfirdaus
Comment options

@devongovett
Comment options

Answer selected by Cuttsy27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants