client/HTML
React State 초기화 하는 방법
void
2020. 2. 14. 10:00
import React, {Component} from 'react';
class App extends Component {
constructor(props){
super(props);
//1. constructor 안에서 state 초기화
this.state = {term: ''};
}
//2. constructor 밖에서는 setState로 state를 초기화해줘야한다.render () {
return <input onChange = {(event) => this.setState({term: event.target.value })} />;
}
};
export default App;