<main></main>
class TextInput extends React.Component {
  constructor(props) {
    super(props);
    this.state = { changeCount: 0 };
    this.inc = this.inc.bind(this);
    this.reset = this.reset.bind(this);
  }
  
  inc() {
    this.setState({ changeCount: this.state.changeCount + 1 });
  }
  
  reset() {
    this.setState({ changeCount: 0 });
  }
  
  render() {
    return (
      <div>
        <p>This text was changed {this.state.changeCount} times</p>
        <input type="text" onChange={this.inc} />
        <button onClick={this.reset}>Clear</button>
      </div>      
    )
  }
}

class ButtonInput extends React.Component {
  constructor(props) {
    super(props);
    this.state = { changeCount: 0 };
    this.inc = this.inc.bind(this);
  }
  
  inc() {
    this.setState({ changeCount: this.state.changeCount + 1 });
  }
  
  render() {
    return (
      <div>        
        <button onClick={this.inc}>This button was clicked {this.state.changeCount} times</button>
      </div>      
    )
  }
}


class App extends React.Component {
  render() {
    return (
      <div>
        <TextInput />
        <TextInput />
        <ButtonInput />
      </div>
    );
  }
}

ReactDOM.render(<App />, document.querySelector('main'));
View Compiled

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

  1. https://cdnjs.cloudflare.com/ajax/libs/react/16.2.0/umd/react.development.js
  2. https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.2.0/umd/react-dom.development.js