Created
November 15, 2018 23:29
-
-
Save getaclue00/0ad89262a04f727998ebd346e57e34fe to your computer and use it in GitHub Desktop.
Stateful vs. Stateless
This file contains hidden or 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
| // https://stackoverflow.com/a/49920844 | |
| // Stateless | |
| const ProjectListComponent = (props) => { | |
| const { handleClick } = props | |
| return ( | |
| <button onClick={handleClick}>Click me</button> | |
| ) | |
| } | |
| class AppComponent extends Component { | |
| handleClick() { | |
| console.log('clicked') | |
| } | |
| render() { | |
| return ( | |
| <ProjectListComponent onClick={this.handleClick} /> | |
| ) | |
| } | |
| } | |
| // Stateful | |
| class ProjectListComponent extends Component { | |
| handleClick() { | |
| console.log('clicked') | |
| } | |
| render() { | |
| return ( | |
| <button onClick={this.handleClick}>Click me</button> | |
| ) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment