When using change event for switch, the change made on switch (On/Off) is gone

I have the following switch component with change event on my application


const ActivitySwitchChanged = (args) => {

    if (accessToken && authorized == "Yes"){

        let packageId = args.event.currentTarget.children[0].id;

        let checked= 0;

        if(args.checked == true){

            checked = 2;

        }

        else if(args.checked == false){

            checked = 1;

        }

        else{

            checked = 0;

        }

        dispatch(updateAction({packageId: packageId, checked: checked, accessToken : accessToken}));

    }

}

<SwitchComponent id={workPackage.packageId} change={ActivitySwitchChanged} cssClass='custom-switch'/>


The change event on switch gets triggered on change and performs the action as expected.
However the change that is done is not persisted after the event.

i.e, If I toggle the Switch On, the change event triggeres with args.checked = true and performs the actions. On finishing that method, the Switch however would remain in Off stage.

This happens vice versa as well.

I need the change/toggle I make to be persisted in the Switch component


1 Reply

TS Thaneegairaj Sankar Syncfusion Team April 12, 2022 10:28 AM UTC

Hi Aravind,


We are unable to replicate the issue in our end. We have prepared a sample, please find the below link


Sample: https://stackblitz.com/edit/react-mlzcvb-yrcdcd


We suspect the you are overriding the checked value in updateAction method. If you are still facing issue, please share the below details.


  • Share us the issue replicable sample or replicate the issue in above sample.
  • Share us the code snippet used in updateAction method.


Please provide the above requested information, based on that we will check and provide you a better solution quickly.


Regards,

Thaneegairaj S


Loader.
Up arrow icon