[英]Modal is in child component where the button is in parent component how to close the modal in reactjs
I have tried some of the methods, it could able to solve my solutions these are example: this is the Parent Component:我尝试了一些方法,它可以解决我的解决方案,例如:这是父组件:
const[openup,setOpenup]=useState(false)
const setSchedule =() => setOpenup(true)
<Button onClick={setSchedule} >Openup</Button>
<Child open={openup} />
this is the Chile Component:这是智利部分:
export default function CreateSchedule(props) {
const [show, setShow] = useState(props.open);
const handleClose =() => setShow(false)
return(
<div>
<Modal className='dummy' show={show} onHide={handleClose}>
Its not working working !!!
</Modal>
</div>
)
}
Could any one get rid of this one, ...有没有人能摆脱这个,...
Assuming Child is the CreateSchedule commponent, you can redesign your code structure so that the parent is controlling thee rendering of Modal by passing in props like open and also the function to close the modal假设 Child 是 CreateSchedule 组件,您可以重新设计代码结构,以便父级通过传递诸如 open 和 function 之类的道具来控制模态的渲染以关闭模态
Your parent component will look like你的父组件看起来像
const[openup,setOpenup]=useState(false)
const setSchedule =() => setOpenup(true)
const handleClose = () => setOpenup(false);
<Button onClick={setSchedule} >Openup</Button>
<Child open={openup} handleClose={handleClose}/>
Your Child component will be您的子组件将是
export default function CreateSchedule(props) {
return(
<div>
<Modal className='dummy' show={props.open} onHide={props.handleClose}>
Its not working working !!!
</Modal>
</div>
)
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.