0
我使用React和Redux来每次单击按钮时尝试增加道具的值。但道具因某种原因被当作NaN来对待。为什么ES6将此视为NaN?
这是我的减速器:
export default function(){
return 0;
}
而另一个减速机:
export default function (state = null, action) {
switch (action.type) {
case 'VALUE_INCREMENTED':
return action.payload;
break;
}
return state;
}
这是我的行动:
export const incrementValue = (val) =>{
console.log("You incrementend the value to: ", val+1);
return {
type: 'VALUE_INCREMENTED',
payload: val+1
}
};
而这是容器:
class Thermo extends Component{
getValue(){
return this.props.val;
}
render(){
return(
<div>
<Thermometer
min={0}
max={90}
width={10}
height={230}
backgroundColor={'gray'}
fillColor={'pink'}
current={this.props.val}
/>
<input type = "submit" onClick={() => this.props.incrementValue(this.props.val)}value="+"/>
</div>
)
}
}
function mapStateToProps(state){
return{
val: state.val
};
}
function matchDispatchToProps(dispatch){
return bindActionCreators({incrementValue: incrementValue}, dispatch);
}
export default connect(mapStateToProps, matchDispatchToProps)(Thermo);
我不知道React,但很可能'this.props.val'是'undefined'。 –
@Gothdo我粘贴了整个容器代码。我即将编辑它。 –
请发布您的减速机代码,这将是超级有用 – finalfreq