clear form inside modal after close reactjs

Solutions on MaxInterview for clear form inside modal after close reactjs by the best coders in the world

showing results for - "clear form inside modal after close reactjs"
Paul
06 May 2017
1If 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
2
3
4const initialState = { name: null, inStock: null, price: null, type:null }
5
6closeModal = () => {
7        this.setState({ 
8         ...initialState,
9         modalIsOpen: false 
10        });
11    }
12But 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.
13
14const initialState = { name: null, inStock: null, price: null, type:null }
15
16closeModal = () => {
17        this.setState({ 
18         modalIsOpen: false 
19        }, () => {
20        this.props.resetInputData();
21      });
22    }
Phineas
05 Sep 2016
1435435