Search code examples
javascriptreactjsradio-buttonradio-group

how to get the full event object when using RadioGroup in react


hello guys am stuck in a little problem, am using RadioGroup in react and my problem is that i cant get the event object instead i get only the value, in my case i want to get the name and the value when the onChange event fire

 <RadioGroup name="distance" onChange={handleChange}>
     <Radio value="0.5">0.5</Radio>
     <Radio value="2000">1</Radio>
     <Radio value="3000">2</Radio>
     <Radio value="4000">3</Radio>
     <Radio value="5000">4</Radio>
 </RadioGroup>

 const handleChange = (e) => {
    console.log(e);//getting only the value
   
  };

Solution

  • There is two difference in next version (v1.x) and stable version v0.x of chakra-ui

    in <RadioGroup /> (v0.x)

    onChange?: (
        event: React.ChangeEvent<HTMLInputElement>,
        value: IRadio["value"],
      ) => void;
    

    and in <RadioGroup /> (v1.x)

    onChange?(nextValue: StringOrNumber): void;
    

    And if you wanna get access to the event, you may downgrade the version of your chakra-ui