<div className={styles.content}>
{children}
</div>
當(dāng)我們使用數(shù)據(jù)流進(jìn)行數(shù)據(jù)傳遞時(shí){children}此時(shí)便無(wú)法綁定父組件的事件因此我們使用以下的形式
{
React.Children.map(children, (child: React.ReactNode) => {
return React.cloneElement(child as React.ReactElement, {
onChange: () => {
setUpdate(update + 1);
},
});
})
}
interface Props {
onChange?: ()=> void
};
const Page: React.FC<Props> = ({
onChange,
}) => {
return (
<div onClick = { ()=>{
onChange?.()
}}>
</div>
);
}
export default Page;
Vue