Last active
December 2, 2018 10:01
-
-
Save SastraNababan/9d71f255e2ba8b80ffe958e29be0e411 to your computer and use it in GitHub Desktop.
Prop Callback
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default class Parent extends Component { | |
state={ | |
status:true | |
} | |
_changeStatus=(status)=>{ | |
this.setState({status:status}) | |
} | |
render() { | |
return ( | |
<Child | |
status={this.state.status} | |
changeStatus={()=>this.changeStatus}/> | |
) | |
} | |
} | |
export default class Child extends Component { | |
state = { } | |
render() { | |
console.log(this.props.status) //=> true | |
this.props._changeStatus(false) | |
console.log(this.props.status) //=> false | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment