Reputation: 895
I'm having trouble getting the "checked" attribute to work on a radio button in React. Note that the class attribute correctly updates to "selected" when I click the radio button, so the "activeRating.time_felt_right === false" check is working.
<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 is provided by Redux's mapStateToProps. updateActiveRating is defined as follows:
const mapDipsatchToProps = (dispatch) => ({
updateActiveRating (rating) {
dispatch(updateActiveRatingAction(rating));
},
});
Upvotes: 2
Views: 4924