<main></main>
.text-length, .counted-text { 
  font-size: 24px;
}
class CountedText extends React.Component {
  constructor(props) {
    super(props);
    this.state = { text: '' };
    this.setText = this.setText.bind(this);
    this.reset = this.reset.bind(this);
  }

  setText(e) {
    this.setState({ text: e.target.value });
  }

  reset(e) {
    this.setState({ text: '' });
  }

  render() {
    return (
      <p>
        <input
          type='text'
          placeholder='some text...'
          className='counted-text'
          value={this.state.text}
          onChange={this.setText}
          />

        You typed <span className='text-length'>{this.state.text.length}</span> characters
        <button className='btn-reset' onClick={this.reset}>Reset</button>
        {
          (this.state.text.length > 0) &&
            <CountedText />
        }
      </p>
    )
  }
}

class App extends React.Component {
  render() {
    return (
      <div>
        <CountedText />
      </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.4.2/umd/react.development.js
  2. https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.4.2/umd/react-dom.development.js