TIL(2020.12.14)
0. Props
// 구문
<child value = 'value' />
1. state
1-1. ステータスコードの表示
App.js
import React, { Component } from 'react';
import Counter from './Counter'; // Counter.js 불러오기(state내장하고 있는 콤포넌트)
class App extends Component {
render() {
return <counter/ >;
}
}
export default App;
Counter.js stateで使用するコンビネーション構成部品import React, { Component } from 'react';
class Counter extends Component {
state = {
number : 0 // 기본 state 지정. 변화시킬 값(여기서는 number)에 대해 지정
};
constructor(props) {
super(props);
this.handleIncrease = this.handleIncrease.bind(this);
this.handleDecrease = this.handleDecrease.bind(this);
}
handleIncrease = () => {
this.setState({
number : this.state.number + 1
});
};
handleDecrease = () => {
this.setState({
number : this.state.number - 1
});
};
render() {
return (
<div>
<h1>카운터</h1>
<div> 값 : {this.state.number}</div>
<button onClick = {this.handleIncrease}> + </button>
<button onClick = {this.handleDecrease}> - </button>
</div>
);
}
}
export default Counter;
Reference
この問題について(TIL(2020.12.14)), 我々は、より多くの情報をここで見つけました https://velog.io/@skwlalsl93/TIL2020.12.14テキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol