You can use the callback style for the ref
prop to collect all the refs.
Here's a rough example of how this would look.
var refs = {};
function refCollector(id) {
return function(element) {
refs[id] = element;
if(allRefsCollected()) {
// do some work with all refs
}
}
}
function allRefsCollected() {
return Object.keys(refs).length >= children.length;
}
return children.map((Child, index) => {
return <Child ref={refCollector(index)} />;
});
When allRefsCollected
returns true, you'll know that all the children have been rendered and refs
will be an object, mapping id
to element
.