valchann
valchann
SSolidJS
Created by valchann on 8/4/2023 in #support
What is props.children really?
I'm trying to make an element that scrolls it's children automatically when mounted. This is what I have currently:
interface AutoScrollProps {
children: JSXElement
}

function AutoScroll(props: AutoScrollProps) {
onMount(() => {
if (props.children instanceof HTMLElement) {
if (document.body.contains(props.children)) {
console.log("Element is mounted")
} else {
console.log("Element is not mounted")
}
}
})

return props.children
}

/* ... */

<AutoScroll>
<div />
</AutoScroll>
interface AutoScrollProps {
children: JSXElement
}

function AutoScroll(props: AutoScrollProps) {
onMount(() => {
if (props.children instanceof HTMLElement) {
if (document.body.contains(props.children)) {
console.log("Element is mounted")
} else {
console.log("Element is not mounted")
}
}
})

return props.children
}

/* ... */

<AutoScroll>
<div />
</AutoScroll>
It actually prints "Element is not mounted". Does this mean the element that gets mounted in the DOM is a clone of props.children?
10 replies