Reactjs 反应/物料界面-处理子组件中的打开/关闭框
因此,在我的父类中,我当前有以下代码片段:Reactjs 反应/物料界面-处理子组件中的打开/关闭框,reactjs,material-ui,Reactjs,Material Ui,因此,在我的父类中,我当前有以下代码片段: ... return ( <div className={prefix}> {(toEditBooking===true ? <EditBooking editBooking={true} booking={selected}/> : null)} <Paper style={header} rounded={false}> <div className ={
...
return (
<div className={prefix}>
{(toEditBooking===true ? <EditBooking editBooking={true} booking={selected}/> : null)}
<Paper style={header} rounded={false}>
<div className ={prefix+'-name'}>{name}</div>
<div className ={prefix+'-flight'}>{refNo}</div>
<div className ={prefix+'-initials'}>{initials}</div>
<div className ...
。。。
返回(
{(toEditBooking==true?:null)}
{name}
{refNo}
{首字母缩写}
{
this.setState({open:this.props.editBooking})
}
状态={
打开:this.props.editBooking,
};
handleClose=()=>{
this.setState({open:false});
};
渲染(){
常量动作=[
,
,
];
const booking=this.props.booking
控制台日志(预订)
返回(
请更新以下正确的详细信息:
航班详情
这是第一次,但是,如果用户关闭子组件(EditBooking),我希望父组件将其道具更新为
是否有一个容易实现的方法?将另一个道具传递到名为onClose的子组件中,这将是一个回调,子组件在关闭时将调用该回调
<EditBooking editBooking={true} booking={selected} onClose={() => {
// put all your logic to handle closing in the parent component
// e.g. this.setState({ editBooking: false });
}} />
<EditBooking editBooking={true} booking={selected} onClose={() => {
// put all your logic to handle closing in the parent component
// e.g. this.setState({ editBooking: false });
}} />
handleClose = () => {
this.setState({open: false});
this.props.onClose(); // call callback provided by parent
};