admin管理员组文章数量:1355593
I'm trying to set the state according to the input field value (controlled ponents in react js), but the event always results undefined once I try to change the value of the input field.
App.js
initialState = {
set: {
team1Score: 5,
team2Score: 6,
},
};
handleChange(e) {
this.setState({
set: {
team1Score: e.target.value,
team2Score: e.target.value,
}
});
}
render() {
return (
<Match
set = {this.state.set}
handleChange={(e) => {this.handleChange()}}>
)}
Match.js
<ScoreInput
handleChange={props.handleChange}
set={props.set}
/>
ScoreInput.js
const ScoreInput = (props) =>
<div className="c-set-input">
<input
className="c-set-input__field"
placeholder="0"
value={props.set.team1Score}
onChange={props.handleChange}
></input>
<span>:</span>
<input
className="c-set-input__field"
placeholder="0"
value={props.set.team2Score}
onChange={props.handleChange}
></input>
</div>
I'm trying to set the state according to the input field value (controlled ponents in react js), but the event always results undefined once I try to change the value of the input field.
App.js
initialState = {
set: {
team1Score: 5,
team2Score: 6,
},
};
handleChange(e) {
this.setState({
set: {
team1Score: e.target.value,
team2Score: e.target.value,
}
});
}
render() {
return (
<Match
set = {this.state.set}
handleChange={(e) => {this.handleChange()}}>
)}
Match.js
<ScoreInput
handleChange={props.handleChange}
set={props.set}
/>
ScoreInput.js
const ScoreInput = (props) =>
<div className="c-set-input">
<input
className="c-set-input__field"
placeholder="0"
value={props.set.team1Score}
onChange={props.handleChange}
></input>
<span>:</span>
<input
className="c-set-input__field"
placeholder="0"
value={props.set.team2Score}
onChange={props.handleChange}
></input>
</div>
Share
Improve this question
asked Jul 13, 2017 at 13:50
AiwatkoAiwatko
5153 gold badges8 silver badges18 bronze badges
1
-
3
you forgot to pass
e
inhandleChange
function – Abhishek Commented Jul 13, 2017 at 13:52
1 Answer
Reset to default 6It seems that you forgot to pass the parameter to your handleChange function so try this
handleChange={(e) => this.handleChange(e)}
本文标签: javascripte undefined in react js componentStack Overflow
版权声明:本文标题:javascript - e undefined in react js component - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744019854a2577019.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论