0
은 예상 :이것은 왜 컴포넌트 코드가 예상대로 반응하지 않습니까?
- 입력 상자의 텍스트를 변경에서 메시지에 제목 업데이트를 대문자로 변환. 업데이트 된 메시지가
결과 인 콘솔에 인쇄 보내기 버튼을 누르면에
- 이 작동하지 않습니다. 'this'라는 콘솔의 오류가 textBoxChange 함수에서 정의되지 않았습니다. (그것은 렌더링 기능에 있지만 textBoxChange 기능에 정의 된 일이야?)
Codepen : https://codepen.io/r11na/pen/qNKpQX
class App extends React.Component {
textBoxChange(e) {
this.props.text = e.target.value;
};
sendMessage(e) {
console.log("Send message:" + this.props.text);
};
render() {
return (
<div>
<h3>Your Message: {this.props.text.toUpperCase()}</h3>
<MessageBox textBoxChange={this.textBoxChange} sendMessage={this.sendMessage} text={this.props.text}/>
</div>
);
};
};
const MessageBox = (props) => {
return (
<div className="row column">
<textarea onChange={props.textBoxChange} value={props.text}></textarea>
<button onClick={props.sendMessage} className="button">Send</button>
<br/>
</div>
);
};
우선 props에 새로운 값을 할당 할 수 없기 때문에'props' 대신'states'를 사용해야합니다 - https://codepen.io/anon/pen/XKYEVG. –
감사합니다 알렉산더가 말이됩니다! – Riina