Last active
October 26, 2021 11:30
-
-
Save literat/9015737369f2b6ed2b66af38669f3539 to your computer and use it in GitHub Desktop.
React test
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
| import React, {Component} from 'react'; | |
| class Counter extends Component { | |
| constructor(props) { | |
| super(props) | |
| } | |
| render() { | |
| <p>Counting: {this.props.count}</p> | |
| } | |
| } | |
| class CountHeader extends Component { | |
| constructor(props) { | |
| super(props) | |
| } | |
| render() { | |
| <h1>Count is : {this.props.count}</h1> | |
| } | |
| } | |
| class CountBody extends Component { | |
| constructor(props) { | |
| super(props) | |
| } | |
| render() { | |
| <div> | |
| I want to count something | |
| <Counter count={this.props.count} /> | |
| </div> | |
| } | |
| } | |
| class MyComponent extends Component { | |
| constructor(props) { | |
| super(props); | |
| this.state = { | |
| count: props.count || 0 | |
| } | |
| this.onClickHandler = this.onClickHandler.bind(this); | |
| } | |
| onClickHandler(e) { | |
| this.setState({ | |
| count: this.state.count + 1; | |
| }) | |
| } | |
| render() { | |
| return ( | |
| <div> | |
| <CountHeader count={this.state.count} /> | |
| <CountBody count={this.state.count} /> | |
| <button onClick={onClickHandler}>Increase Count</button> | |
| </div> | |
| ); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment