打开模态时空道具-React

时间:2018-08-16 14:27:40

标签: reactjs material-ui

在我的父组件中,我有以下代码:

    return (
        <div className={`${this.props.className}`}>
            <CreatePerson
                open={this.state.modalCreate}
                value={this.state.person}
                close={this.changeModalCreate}
            />

            <Grid>
                <Row className='custom-row'>
                    {PersonCards}
                </Row>

                <Button variant="fab" color="primary" aria-label="add" className='button-add' onClick={() => this.changeModalCreate()}>
                    <AddIcon />
                </Button>
            </Grid>
        </div>
    )

我想将我在道具中传递的值置于CreatePerson的状态。

在我单击按钮以打开CreatePerson(这是一个模式)之前,在CreatePerson中使用此构造函数之前,我具有以下对象:

enter image description here

该对象具有我需要的所有属性。但是在单击按钮以打开模态后,所有道具消失了,我得到了以下对象:

enter image description here

(CreatePerson的构造函数)

constructor(props) {
    super(props);
    console.log(props)
    this.state = {}

    this.addProfileImg = this.addProfileImg.bind(this);
    this.removeProfileImg = this.removeProfileImg.bind(this);
    this.addBackgroundImg = this.addBackgroundImg.bind(this);
    this.removeBackgroundImage = this.removeBackgroundImage.bind(this);
    this.addInput = this.addInput.bind(this);
    this.updateText = this.updateText.bind(this);
}

打开模态的功能

changeModalCreate() {
    this.setState((prevState) => ({ ...prevState, modalCreate: !prevState.modalCreate }))
}

0 个答案:

没有答案
相关问题