While not baked into React, this is certainly possible:
import React from "react";
function recursiveMap(children, fn) {
return React.Children.map(children, child => {
if (!React.isValidElement(child)) {
return child;
}
if (child.props.children) {
child = React.cloneElement(child, {
children: recursiveMap(child.props.children, fn)
});
}
return fn(child);
});
}
If you’d like to avoid copy / pasting the above you can also use this npm package I authored.