Answers for "clear form inside modal after close reactjs"

0

clear form inside modal after close reactjs

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();
      });
    }
Posted by: Guest on January-06-2021
0

clear form inside modal after close reactjs

435435
Posted by: Guest on July-24-2021

Code answers related to "clear form inside modal after close reactjs"

Code answers related to "Javascript"

Browse Popular Code Answers by Language