我无法检查"检查"属性来处理React中的单选按钮。请注意,class属性正确更新为" selected"当我点击单选按钮时," activeRating.time_felt_right === false"检查工作正常。
<input type="radio" value="false"
id={`time_felt_right_${activeRating.id}_false`}
checked={activeRating.time_felt_right === false}
className={activeRating.time_felt_right === false ? 'selected' : null}
onChange={e => {
console.log('false');
e.preventDefault()
updateActiveRating({ time_felt_right: false })
}
}
/>
activeRating由Redux的mapStateToProps提供。 updateActiveRating定义如下:
const mapDipsatchToProps = (dispatch) => ({
updateActiveRating (rating) {
dispatch(updateActiveRatingAction(rating));
},
});
答案 0 :(得分:7)
如果您删除e.preventDefault()
它应该有用