Skip to content

Instantly share code, notes, and snippets.

@SastraNababan
Last active December 2, 2018 10:01
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SastraNababan/9d71f255e2ba8b80ffe958e29be0e411 to your computer and use it in GitHub Desktop.
Save SastraNababan/9d71f255e2ba8b80ffe958e29be0e411 to your computer and use it in GitHub Desktop.
Prop Callback
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