ReactJSを手直しして簡単な例を扱っています。すごくうまくいっていて、私はすでに生産性が向上していると感じています。今、私はEnterキーが押されたときにアプリケーション名をコンソールに記録する簡単なReactの例を取り上げています。入力ボックスにアプリケーション名を入力してEnterキーを押すまで、すべて正常に動作しますが、コンソールログに表示されるのは入力値ではなく、「未定義」値です。ここには完全なJSコードがあります:Reactコンポーネントの小道具へのアクセス
"use strict";
var InputText = React.createClass({
render() {
return <div><p>Please input the app name you wish to access:</p></div>
}
});
var InputBox = React.createClass({
onKeyPress(e) {
if (e.key === 'Enter') {
console.log(this.props.value);
}
},
render() {
return <input type="text" onKeyPress={this.onKeyPress}></input>
}
});
var AppForm = React.createClass({
render() {
return <div class="appForm">
<InputText />
<InputBox />
</div>
}
});
var App = React.createClass({
render() {
return <AppForm />
}
});
ReactDOM.render(
<App />,
document.getElementById("container")
);