According to the documentation:
Clone and return a new React element using element as the starting
point. The resulting element will have the original element’s props
with the new props merged in shallowly. New children will replace
existing children. key and ref from the original element will be
preserved.
A valid use case for cloneElement is when you wish to add one/more props to the elements passed a children by the parent.You would simply map over all the children and clone them by adding new props for instance.
return (
<div style={styles}>
{React.Children.map(children, child => {
console.log(child);
return React.cloneElement(child, {newProp}, null);
})}
</div>
)
Check a working demo