20230518

<< [[20230517]] | [[20230519]]>>

TODO


PL(C)

(강의) 웹게임을 만들며 배우는 React

클래스 메서드

  • 직접 선언한 함수들은 화살표함수를 사용해야함 -> function을 사용할 경우 this가 달라지기 때문

      onSubmit = (e) => {
        e.preventDefault();
        if (this.state.first * this.state.second === parseInt(this.state.value))
          this.setState({
            result: "O",
            first: Math.ceil(Math.random() * 9),
            second: Math.ceil(Math.random() * 9),
            value: ''
          })
        else this.setState({ result: "X", value: '', })
      }
  
      onChange = e => this.setState({ value: e.target.value })
  • 실무에선 constructor 사용 안함

	    // constructor(props) {
      //   super(props);
      //   this.state = {
      //     first: Math.ceil(Math.random() * 9),
      //     second: Math.ceil(Math.random() * 9),
      //     value: '',
      //     result: '',
      //   }
      // }
      state = {
        first: Math.ceil(Math.random() * 9),
        second: Math.ceil(Math.random() * 9),
        value: '',
        result: '',
      }

Last updated