を反応させますテキストボックスからの入力に基づいてさまざまなパラメータを持つ新しいクラスを作成し、その値を表示します。どのようにしてレンダリングメソッドの内部からそのメソッドを呼び出すのですか?これは、やや私の問題を示しが、私はこのフォームのクラスを持っているコンポーネント
class fixedBlock extends Component {
constructor(){
super()
this.state = {
"textInput":"",
"totalMem":0,
"fixed":null
}
}
handleInputChanged(e){
this.setState({
"textInput":e.target.value
})
}
handleButtonPressed(){
this.setState({"fixed":new Fixed(parseInt(this.state.textInput))})
}
incrementButtonPressed(){
this.state.fixed.addMem(2)
}
render(){
return(
<div>
<input type="button" onClick={this.handleInputChanged} value=
{this.state.textInput}>
<button onClick={this.handleButtonPressed}>create</button>
<button onClick={this.incrementButtonPressed}> increment </button>
<p>{this.state.fixed.totalMem}</p>
</div>
)
}
}
私は、コンポーネントの反応内側ので、これは、私はこの問題を解決するために持っていた別のアプローチは、クロージャを使用していた動作しません。
class fixedBlock extends Component{
constructor(){//stuff here}
FixedMem() {
var FixedObj = null
return {
initFixed: function (totalMem) {
FixedObj = new Fixed(totalMem, divisions)
},
totalMem: function() {
return FixedObj.totalMem
},
increment: function(){
FixedObj.addMem(2)
}
render(){//stuff here}
}
を私もしてこれを使用するにはどうすればよいですレンダリングメソッド?