Skip to content

MenuItem cannot be rendered outside a collection. #7020

Answered by NickWoodward
NickWoodward asked this question in Q&A
Discussion options

You must be logged in to vote

Thanks, I'm not very familiar with Astro. What restrictions does it have on layouts? Can you render things with context? Does it run useEffects? Is the client:load thing needed to make it work?

:)

Your questions made me notice the problem, thanks! The code works fine inside a React component, but not nested as children in an .astro file like that. So yes, you're right, it was restrictions on the layout (or more specifically the astro file).

Other answers: Context - no, useEffect -no, client:load yes, it's needed to provide interactivity.

Here's it working if you're interested: https://stackblitz.com/edit/withastro-astro-xkekzy?file=src%2Flayouts%2FLayout.astro

Thanks again!

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@NickWoodward
Comment options

@snowystinger
Comment options

@NickWoodward
Comment options

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