Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

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();
      });
    }
Comment

PREVIOUS NEXT
Code Example
Javascript :: js convert string to date 
Javascript :: how to change port in react js 
Javascript :: angular right click action 
Javascript :: Material-ui add photo icon 
Javascript :: indexof method 
Javascript :: remove first element of array javascript 
Javascript :: define an async function 
Javascript :: disabling ctrl + s using javascript 
Javascript :: operator to return specific data of a mongodb query 
Javascript :: Get the url and parse or url.parse deprecated solved 
Javascript :: javascript get content of input 
Javascript :: js array index 
Javascript :: react-native-community/blur 
Javascript :: async await in javascript 
Javascript :: jquery values to array 
Javascript :: popup javascript 
Javascript :: get all a elements javascript 
Javascript :: JavaScript find the shortest word in a string 
Javascript :: javascript change right click menu 
Javascript :: javaScript Math.log2() Method 
Javascript :: pop up notification using jquery 
Javascript :: dropzone react view photo 
Javascript :: how to make alert in javascript 
Javascript :: check all checkboxes on table 
Javascript :: mongoose filter 
Javascript :: javascript add text to textarea overwrite 
Javascript :: card type through card number 
Javascript :: js detect user mobile 
Javascript :: moment all formats in reactjs 
Javascript :: nestjs 
ADD CONTENT
Topic
Content
Source link
Name
6+9 =