Reactにはかなり新しく、いくつかのチュートリアルを経て、私は下のコードを試していました。onChangeリスナーでもReactで入力値を変更できないのですが
私は1つのコンポーネントを作成し、店舗からそのコンポーネントに渡しました。componentWillMount
コンポーネントの新しい状態を作成します。レンダリングは今までは問題ありません。
次入力ボックスの値にstate
をバインドしました。私はonChange
リスナーも持っています。それでも、私はフィールドで自分の価値を変えることはできません。
私は角度の背景から来ているので、私はバインディング入力の値を次のように状態に仮定すると、の入力が自動的にstate
オブジェクトのname
に更新されます。私はここに間違っていますか?
componentWillMount(){
this.setState({
updatable : false,
name : this.props.name,
status : this.props.status
});
}
//relevant DOM from component's render function
<input className="form-control" type="text" value={this.state.name} id={'todoName' + this.props.id} onChange={this.onTodoChange.bind(this)}/>
onTodoChange(){
console.log(this);
//consoling 'this' here, shows old values only.
//not sure how and even if I need to update state here.
// Do I need to pass new state to this function from DOM
//TODO: send new data to store
}
マイonTodoChange
機能コンソール初期化中などの状態の同じ値を有するthis
の値。入力ボックスを入力して状態を変更すると、店に送ることができます。
ありがとうを。私はコンストラクタがデフォルトで 'props'を受け取ると仮定しています。正しい?? –
はい、そうです –