Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

pass setstate to child

//ChildExt component
class ChildExt extends React.Component {
    render() {
        return (<div><button onClick={() => this.props.handleForUpdate('someNewVar')}>Push me</button></div>
        )}
}
//Parent component
class ParentExt extends React.Component {
  constructor(props){
    super(props);
    this.state = {lol: false }
  }

    handleForUpdate(someArg){
            this.setState({lol: true});
      		console.log(someArg);
    }
  //Notice how we don't pass the arguments into the bind.this even though it does take an argument.
    render() {
        return (<ChildExt handleForUpdate={this.handleForUpdate.bind(this)} />)
    }
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: model export in node js 
Javascript :: Different between for of loop and for in loop in js 
Javascript :: pull out only text from element javascript 
Javascript :: javascript update multiple values of an object 
Javascript :: service worker registration 
Javascript :: get browser cookie 
Javascript :: what is after.js 
Javascript :: js html object 
Javascript :: how to find a name of class from page in jquery 
Javascript :: javascript focus on contenteditable not working 
Javascript :: props navigation in class component 
Javascript :: How to pass data in Link of react-router-dom 
Javascript :: mongodb add 1 to field 
Javascript :: react change background image on hover 
Javascript :: for each array 
Javascript :: async function in variable 
Javascript :: python minify json 
Javascript :: next js cookie 
Javascript :: Match an object in a string using ReGex 
Javascript :: js check if map contains key 
Javascript :: javascript for of loop 
Javascript :: how to append data to a form data in javascript 
Javascript :: middleware in node js 
Javascript :: jquery determine empty value radio by name 
Javascript :: export table data to excel using javascript or jquery 
Javascript :: javascript array iteration methods 
Javascript :: jquery get padding top without px 
Javascript :: new date javascript invalid date 
Javascript :: mongoose in nodem js 
Javascript :: how to check characters inside a string javascript 
ADD CONTENT
Topic
Content
Source link
Name
2+1 =