简体   繁体   中英

How to change props in a component passed into another component as props

I have a Screens component being passed into a Modal component as the screens prop. Inside Modal I'm rendering it thusly...

{props.screens()}

This displays fine but I need a way to change the Screens components props from within Modal.

You could use React.cloneElement , which allows you to clone an element and add new props.

function myComponent(props) {

return <> {React.cloneElement(props.screens, {someNewProp:"value"}, children)} </>;

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM