아하
생활

생활꿀팁

수줍은이구아나17
수줍은이구아나17

React,js constructor질문입니다

import React, { Component } from 'react'; import './App.css'; class Test extends Component { constructor(props) { super(props); this.state = { value: 2 }; } this.state = { value: 2 }; //취소 render() { this.state = { value: 2 };//답변보고 이쪽에 다시 적었습니다 return ( <div className="App"> </div> ); }} export default Test;

constructor을 사용하지 않은 state와 그렇지않은 state는 어떤차이가 있는걸까요 코드상 위 아래 부분의 차이를 알려주세요!

그리고 state라고 약속하고 쓰는거같은데 변수로 따로 만들어서 저것과 동일하게 사용이 가능한지

가능하시면 간단한 예제 보여주실수있을까요

    2개의 답변이 있어요!