Skip to content

Instantly share code, notes, and snippets.

@literat
Last active October 26, 2021 11:30
Show Gist options
  • Select an option

  • Save literat/9015737369f2b6ed2b66af38669f3539 to your computer and use it in GitHub Desktop.

Select an option

Save literat/9015737369f2b6ed2b66af38669f3539 to your computer and use it in GitHub Desktop.
React test
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