How to validate radio button inside reducer using the event object passed to the reducer?

I have the following reducer in my React app:

const initialState = {
    genderRadio : false,
    ageRadio : false
}

const reducer = (  state = initialState , action ) => {

    switch(action.type) {
        case "VALI_RADIO_INP":
            console.log(action.payload.target);
            return state        
    }
    return state;
}

export default reducer;

action.payload is basically the event object that is passed to the reducer, like so from my component:

validateRadioInput : (e) => dispatch({ type: 'VALI_RADIO_INP' , payload : e })

What I would like to do in my reducer is check if the input element has been checked or not and update the state. How do I using the event object check if a element is checked or not checked?

NOTE::-

Before integrating redux I was checking if the checkbox is checked calling a method that resided right inside my component like so:

Array.from(document.getElementsByName('customer_gender')).some( (elem , idx) => {  return elem.checked  }) 

But of course I can’t use this anymore; any suggestions on how I can validate the checkbox in my reducer using the event object?

31 thoughts on “How to validate radio button inside reducer using the event object passed to the reducer?”

  1. 924385 417794Amazing beat ! I wish to apprentice whilst you amend your web site, how could i subscribe for a weblog internet site? The account aided me a acceptable deal. I had been slightly bit acquainted of this your broadcast provided bright clear concept 421268

    Reply

Leave a Comment