javascript - React - How do I give each child component a unique ref? -
i have parent component renders 1 of several child components:
class parent extends react.component { ... render() { const activechild = this.state.activechild; // 0, 1, 2, etc. return ( <div> {this.props.children[activechild]} </div> ); } } each of these child components needs have ref own unique dom node. in case, need pass each child's node third-party library draw on (for example: visualization, canvas, or map).
the problem that, when child components rendered same 'point' in react tree, @ different times, end sharing same ref. (i think)
here's jsfiddle demonstrating problem, using leaflet.js.
when of children rendered separately, each own dom node draw map onto. when shown one-at-a-time, first 1 able draw onto ref'd dom node.
can tell react use (and display) separate nodes each individual child's ref, if children being mounted @ same point?
if not, there better approach problem?
Comments
Post a Comment