import React, { Component } from 'react';
import './App.css';

class App extends Component {
  state = {
    password: '',
    clicked: false,
    validated: false
  }

  handleChange = (e) => {
    this.setState({
      password: e.target.value
    })
  }

  handleButtonClick = () => {
    this.setState({
      clicked: true,
      validated: this.state.password === '0000'
    })
  }

  render() {
    return (
      <div>
        <input type="password" value={this.state.password} onChange={this.handleChange}
          className={this.state.clicked ? (this.state.validated ? 'success' : 'failure') : ''} />
        <button onClick={this.handleButtonClick}>ok</button>
      </div>
    )
  }
}

export default App;

ref를 꼬옥 사용할 필요가 있을 때, 그때 보자..

컴포넌트 반복