I have added radio button group to may reactjs app. here the problem is when i try to log the value i get the value of previous radio button instead of getting current button value.
eg. Suppose When i click on go from all to awaited then this logs all.
I don't know what is causing this issue.
my Code
const [radioValue, setRadioValue] = React.useState("all");
function handleChangeRadio(event) {
const value = event.target.value;
setRadioValue(value);
console.log(radioValue); <---- Here When i try to log the value. it shows the value of previous button.
}
<RadioGroup
className={classes.radioGroup}
aria-label="status"
name="status"
value={radioValue}
onChange={handleChangeRadio}
row
>
<FormControlLabel
checked={radioValue === "all"}
value="all"
control={<Radio color="primary" />}
label="All"
labelPlacement="end"
className={classes.radioLabel}
/>
<FormControlLabel
checked={radioValue === "approved"}
value="approved"
control={<Radio color="primary" />}
label="Approved"
labelPlacement="end"
className={classes.radioLabel}
/>
<FormControlLabel
checked={radioValue === "awaited"}
value="awaited"
control={<Radio color="primary" />}
label="Awaited"
labelPlacement="end"
className={classes.radioLabel}
/>
<FormControlLabel
checked={radioValue === "on_hold"}
value="on_hold"
control={<Radio color="primary" />}
label="On Hold"
labelPlacement="end"
className={classes.radioLabel}
/>
</RadioGroup>