vidom
vidom copied to clipboard
how to get ref of a child?
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))
})
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.
Well actually it's in the docs https://github.com/dfilatov/vidom/wiki/ComponentNode-API
child.getDomNode() returns null for me
Sorry for outdated doc (
child.getDomNode() returns null for me
Maybe because you call it before child is rendered to DOM?