Recursive component

Is there any way to have a component that renders itself recursively? E.g. a menu item with children, that can also render itself. (As long as the child’s item still has children.)

I wanted to do it today but saw an error “A component cannot render itself.” or something like that, while trying to accomplish that.

For now as a workaround I’ve created a few copies of a “MenuItem” component, e.g. Item1 Item2 Item3, where Item1 renders Item2s, Item3 renders Item3s… But this forces me to build and maintain more components than needed.

Wondering if there’s any better way to accomplish that?

Hi, it’s not possible to expressly renders components recursively, but you could try to model it in a different way, having Menu, MenuGroup, MenuItem. Then with slots you could add a MenuGroup inside a MenuGroup for example.