[React:State、Props、Event-1.Stateを使用]
State
Props
App.js
import React from 'react';
class State extends React.Component {
constructor() {
super();
this.state = {
color : 'red'
};
}
render() {
return (
<div>
<input style={{color : this.state.color}} type="text" value="id">
</input>
<button>로그인</button>
</div>
);
}
}
export default State;
:constructorで指定したステータスプロパティ{color}からrender関数で入力した値にアクセスし、inlineスタイルで受信します.
<input style=
{{color : this.state.color}}
type="text" value="id”>
// this : 해당 컴포넌트
// this.state : 해당 컴포넌트의 state 객체
// this.state.color : state 객체의 특정 key(color)값.
つまり、「赤」状態(オブジェクト自体)のオブジェクト属性を使用して、オブジェクトキー値にアクセスするようにstyleを適用します!index.js
import React from 'react';
import ReactDOM from 'react-dom';
import State from './App';
ReactDOM.render(<State />,
document.getElementById('root'));
Stateでステータス値を設定する理由は、コンポーネント内の要素にステータス値を反映して画面に表示するためです(UI).2つのステータスにアクセスし、inline styleで同時に適用します.
import React from 'react';
class State extends React.Component {
constructor() {
super();
this.state = {
color1 : ‘red’,
color2 : 'white’,
backgroundColor : 'blue'
};
}
render() {
return (
<div>
<input
style={{color : this.state.color1}}
type="text" value="id">
</input>
<button
style={{backgroundColor : this.state.backgroundColor,
color : this.state.color2}}>
로그인</button>
</div>
);
}
}
export default State;
:ボタン内のinline styleに2つのステータス値を適用する場合.{ { style1 : state1 , style2: state2 } }
オブジェクトを作成するように、オブジェクトを「,」に分類して適用するかどうかを決定します.Reference
この問題について([React:State、Props、Event-1.Stateを使用]), 我々は、より多くの情報をここで見つけました https://velog.io/@ichbinmin2/React-State-Props-Event-실습-1.-state-활용テキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol