I use a simple input field which should be controlled by an @observable value:
<div>
<input value={this.props.appState.myValue} onChange={this.handleChange}/>
value: {this.props.appState.myValue}
</div>
After updating myValue to undefined the displayed value changes, but the value in the input field keeps the same value.
Initial state:
[initial]
value: initial
After update:
[initial]
value:
I use a simple input field which should be controlled by an @observable value:
<div>
<input value={this.props.appState.myValue} onChange={this.handleChange}/>
value: {this.props.appState.myValue}
</div>
After updating myValue to undefined the displayed value changes, but the value in the input field keeps the same value.
Initial state:
[initial]
value: initial
After update:
[initial]
value:
Share
Improve this question
edited Dec 27, 2016 at 15:25
Tholle
113k22 gold badges208 silver badges197 bronze badges
asked Dec 27, 2016 at 14:58
Matthias MMatthias M
15k18 gold badges98 silver badges129 bronze badges
1 Answer
Reset to default 5I would suspect you are not making your ponent into an observer. Try this example:
@observer
class App extends React.Component {
handleChange = (e) => {
this.props.appState.myValue = e.target.value;
};
render() {
const { appState } = this.props;
return (
<div>
<input value={appState.myValue} onChange={this.handleChange} />
value: {appState.myValue}
</div>
);
}
}
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745350301a4623792.html
评论列表(0条)