-
Not sure how to code but there couple ways but I wonder how to detect element create and added. I am trying to create simple three.js build test. But knowing that it can't init since it not create element yet.
Will get error. I wanted to know simple way to set up when it mount detect and create the 3d web gl. Well I wish there was better way to find thing on search engine is trouble since base other topics and not match. There should be some helper scripts or add on what the user needs for it. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 5 replies
-
Sorry @Lightnet I don't quite understand what exactly you want to achieve. Could you elaborate? What is the error message you got? |
Beta Was this translation helpful? Give feedback.
-
I try to understand this discussion. Sometimes we want to do something after the element mount to document. In React, we can do this by const Component = () => {
useEffect(() => {
// this element is outside of current component
const el = document.querySelector('...')
}, [])
return <>...<>
} Move back to VanJS: const Component = () => {
// the el is null
const el = document.querySelector('...')
return <>...<>
} The workaround is use timeout, but I'm not sure if this can work for all cases: const Component = () => {
setTimeout(() => {
const el = document.querySelector('...')
}, 0)
return <>...<>
} And also, sometimes we want to do someting when component is removed from the DOM. It is really useful for scenarios like data tracking, accessibility, ... Will it be difficult to add a lifecycle called when component is mount/unmount to the DOM ? |
Beta Was this translation helpful? Give feedback.
Sorry. It took time to do some work. Is there way to detect element add to document render.
Might be incorrect way to set up. I wanted to see if there way to detect element change. I guess it not render yet.