I have one object I want to compare that key value with string yes or no I am trying to reach it but that is not working correctly need to compare that and then the radio button will get checked with accordingly yes or no need to handing change with that also.
const screenJson = {
Management: "yes",
Configuration: "no",
Rule: "no",
Initiate: "yes",
DM: "no",
Download: "yes",
Dashboard: "no",
}
const [selectedValue, setSelectedValue] = React.useState(screenJson);
// ...
const handleChange = (event) => {
const copyOfModuleSubModules = _.cloneDeep(selectedValue);
Object.keys(copyOfModuleSubModules[event.target.name]).forEach((item) => {
console.log(copyOfModuleSubModules[event.target.name]);
console.log('dd', event?.target?.value);
copyOfModuleSubModules[event.target.name][item] = event?.target?.value;
});
setSelectedValue({
..._.cloneDeep(copyOfModuleSubModules),
});
};
<>
{
Object.keys(screenJson)?.map((data, index) => (
<Grid item key={index} mt={2} xs={12} container>
<Grid item xs={6} mt={2} textAlign="left">
<Typography variant="body1">{data}</Typography>
</Grid>
<Grid item xs={3}>
{JSON.stringify(
Object.values(screenJson)
.filter(data => data)
.toString() === "yes"
)}
<Radio
checked={
Object.values(screenJson)
.filter(data => data)
.toString() === "yes"
}
onChange={handleChange}
value="a"
name={data}
inputProps={{ "aria-label": "A" }}
/>
</Grid>
<Grid item xs={3}>
<Radio
checked={screenJson?.[Object.keys(screenJson)] === "no"}
onChange={handleChange}
value="b"
name={data}
inputProps={{ "aria-label": "A" }}
/>
</Grid>
</Grid>
))
}
</>