Issue
Say I have the following component, how would I iterate over and render each child to do stuff like wrapping each child with other components?
interface StuffProps {
children: `?`
}
function Stuff({ children }: StuffProps) {
// ?
}
I've tried setting children: JSX.Element
and then doing <For each={children}> ... </For>
but it gives me a typescript error.
Solution
Not sure if this is right, but I may have found an answer using the children
helper function provided by solid-js (api docs).
My solution looks something like this:
import { JSX, children } from 'solid-js';
interface StuffProps {
children: JSX.Element
}
function Stuff(props: StuffProps) {
const cs = children(() => props.children).toArray()
<For each={cs}> ... </For>
}
Answered By - gxc
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.