perms is an array of objects. Each object is:
{
catg: 'Catg1'
serv: ->array of serv objects
{
checked: false,
desc: 'Serv 1'
}
}
On button click, based on the catg sent, I need to update all checked to true for each serv object for that catg. Code is as below:
const [perms, setPerms] = useState<any[] | null>(null);
const handleClick = (
event: React.MouseEvent,
catg: string
) => {
const permCopy = [...perms];
const catgPerm = permCopy?.filter(function (perm) {
return perm.catg === catg;
});
const catgServs = perms?.servs;
catgServs.map((serv, index) => {
const updatedServ = { ...serv, checked: true };
catgServs[index] = updatedSer;
});
}
setPerms(permCopy);
The screen is not re-rendering and it does not reflect the updated check boxes. I suspect the state variable is not getting updated.
The data looks like this:
perms = [
{
catg: 'Catg1',
servs: [
{
desc: 'Serv1',
checked: false,
},
{
desc: 'Serv2',
checked: false,
},
{
desc: 'Serv3',
checked: false,
}
]
},
{
catg: 'Catg2',
servs: [
{
desc: 'Serv4',
checked: false,
},
{
desc: 'Serv5',
checked: false,
},
{
desc: 'Serv6',
checked: false,
}
]
}
]
perms, and specifically what the new data should be? It looks like you're generally confused on the structure of your data, and the structure shown is more of a general description of the data than an actual example.