You can utilize the React.cloneElement function. This function allows you to clone a React element and pass new props to it, effectively overriding the existing ones.
Example:
import React from 'react';
const ParentComponent = ({ children }) => {
const modifiedChildren = React.Children.map(children, child =>
React.cloneElement(child, { newProp: 'newValue' })
);
return <div>{modifiedChildren}</div>;
};
const ChildComponent = ({ newProp }) => {
return <div>{newProp}</div>;
};
// Usage
<ParentComponent>
<ChildComponent />
</ParentComponent>