📜  关闭reactjs后清除模态内的表单 - Javascript代码示例

📅  最后修改于: 2022-03-11 15:01:12.831000             🧑  作者: Mango

代码示例1
If the data from the inputs is in your component you can try something like this : In closeModal you can set the initial state of the component


const initialState = { name: null, inStock: null, price: null, type:null }

closeModal = () => {
        this.setState({ 
         ...initialState,
         modalIsOpen: false 
        });
    }
But if the stat of the inputs is coming from the Parent you need a new method to reset the data of the parent component that cpuld be added as a callback in the same method.

const initialState = { name: null, inStock: null, price: null, type:null }

closeModal = () => {
        this.setState({ 
         modalIsOpen: false 
        }, () => {
        this.props.resetInputData();
      });
    }