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)} />)
}
}
Also in JavaScript:
- javascript test regex date with slashes
- resize image react native
- js opposite of preventdefault
- date time react component
- how to wait for a function to finish in javascript
- count value a to b character javascript
- angular maxlength directive input type number
- javascript base64 encode string
- include other js files in a js file
- js toggle boolean
- open bytes in new tab angular
- create fooer on print page with jquery
- Convert JS Object to form data Ask Question
- how to allow implicit any in .d.ts
- nodejs shebang
- jquery empty and append
- javascript get data attribute value
- Material-ui clock icon
- angular dynamic class
- set readonly in javascript
- switch two values each case js
- créer composant react
- string concatenation in js
- Drupal 8 get page node current path