Daniel
Daniel

Reputation: 895

Radio button checked not working in React

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

Answers (1)

Uziel Valdez
Uziel Valdez

Reputation: 2280

if you remove the e.preventDefault() it should work

Upvotes: 11

Related Questions