Skip to content

Instantly share code, notes, and snippets.

@flavioribeirojr
Last active October 30, 2018 12:01
Show Gist options
  • Save flavioribeirojr/3379989b4acf6633ca45887efe8b2886 to your computer and use it in GitHub Desktop.
Save flavioribeirojr/3379989b4acf6633ca45887efe8b2886 to your computer and use it in GitHub Desktop.
Fluxo de componentes pai > filho
import React, { Component } from 'react'
class Filho extends Component {
render() {
const onClick = this.props.onClick
return (
<div>
<button onClick={() => onClick()}>
Click me!
</button>
</div>
)
}
}
class Pai extends Component {
constructor(props) {
super(props)
this.state = {
count: 0
}
}
incrementCount() {
this.setState({
count: this.state.count + 1
})
}
render() {
return(
<div>
<h1> Contadot: { this.state.count }</h1 >
<Filho onClick={this.incrementCount.bind(this)} />
</div>
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment