Last active
October 30, 2018 12:01
-
-
Save flavioribeirojr/3379989b4acf6633ca45887efe8b2886 to your computer and use it in GitHub Desktop.
Fluxo de componentes pai > filho
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
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