Last active: 2 years ago
Pass props to React children
const childrenWithProps = React.Children.map(children, (child) => {
if (React.isValidElement(child)) {
return React.cloneElement(child, {
showContent: child.props.value === currentValue,
});
}
return child;
});
/**
* Pass onLoad funtion to Suspense child
*/
const childrenWithProps = React.Children.map(children, (child) => {
if (!React.isValidElement(child)) return child;
const demoChild = React.Children.map(
child.props.children as ReactElement<DemoProps>,
(child) => {
if (!React.isValidElement(child)) return child;
return React.cloneElement(child, {
onLoad: handleChildLoad,
});
}
);
return React.cloneElement(child, {
children: demoChild,
});
});