class List extends Component {
<DoSomethingToList>
{this.props.list.map(item => <Item key={item} ref={item} />}
</DoSomethingToList>
}
class DoSomethingToList extends Component {
componentDidUpdate(prevProps) {
// I want to access refs here
let refs = this.refs
// refs === {} ------> Why is this happening?
}
render() {
<div>
{this.props.children}
</div>
}
}
I want to be able to access children as refs in the lifecycle methods of the wrapper component. This is so I can keep track of previous instances of domNodes for animations. But whenever I access refs, they return as an empty object. What is the React-friendly way of accessing the refs in lifecycle methods?