vidom icon indicating copy to clipboard operation
vidom copied to clipboard

how to get ref of a child?

Open LexRiver opened this issue 5 years ago • 3 comments

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))
})

LexRiver avatar Dec 26 '19 08:12 LexRiver

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.

dfilatov avatar Dec 26 '19 08:12 dfilatov

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

child.getDomNode() returns null for me

LexRiver avatar Dec 26 '19 10:12 LexRiver

Sorry for outdated doc (

child.getDomNode() returns null for me

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

dfilatov avatar Dec 26 '19 11:12 dfilatov