dfilatov / vidom

Library to build UI based on virtual DOM
MIT License
415 stars 16 forks source link

how to get ref of a child? #357

Open LexRiver opened 4 years ago

LexRiver commented 4 years ago

How can I get a DOM ref of a child? Previously I was able to get by .setRef(), but now I'm getting error child.setRef is not a function even for class-component children. What am I missing?

this.children.map(child => {
   child.setRef(ref => console.log('ref=', ref))
})
dfilatov commented 4 years ago

setRef was never be a public api.

You can try to use child.getDomNode() but I wouldn't recommend using such a way since there's no any guarantee that this.children is an array of component nodes.

LexRiver commented 4 years ago

Well actually it's in the docs https://github.com/dfilatov/vidom/wiki/ComponentNode-API

child.getDomNode() returns null for me

dfilatov commented 4 years ago

Sorry for outdated doc (

child.getDomNode() returns null for me

Maybe because you call it before child is rendered to DOM?