我正在react.JS中进行一个小的多选题测验,其中我有一些单选按钮,并希望基于传入的点来创建基于点的系统。
state={
points: 0
}
questionHandler = event =>{
let value = event.target.value
if(value = 'answer1'){
}else if(value = 'answer2'){
//do something else
}else{
//do a third thing
}
}
问题是我无法将状态更改为以前的状态
questionHandler = event =>{
let value = event.target.value
if(value = 'answer1'){
}else if(value = 'answer2'){
//this would just concat the score
this.setState({points: [...this.state.points, 20]
}else{
//do a third thing
}
}
我该如何进行检查,以使状态仅设置为一个还是单选按钮?
是否还需要为每个问题设置处理程序,或者有一个通用的解决方案?