I want to update my boolean data while displaying in Switch in each row (data fetched from firestore )
The data is being displayed correctly but while clicking on it to change it either true of false it's not working. Here is my code..
{
name: "is_verified",
label: "Verified",
options: {
customBodyRender: (value, tableMeta, updateValue) => {
return (
<Switch
checked={value}
onChange={
async (e) => {
e.preventDefault();
//tableMeta.rowData[0] is my document id
const docsRef = doc(db, "vendors" , tableMeta.rowData[0])
await updateDoc(docsRef, {
value: e.target.checked,
})
}
}
name="active"
color="primary"
/>
)
}
}
}
Issue Solved
{
name: "is_verified",
label: "Verified",
options: {
customBodyRender: (value, tableMeta, updateValue) => {
return (
<Switch
checked={value}
onChange={
async (e) => {
e.preventDefault();
updateValue(e.target.checked);
//tableMeta.rowData[0] is my document id
const docsRef = doc(db, "vendors" , tableMeta.rowData[0])
await updateDoc(docsRef, {
is_verified: !value,
})
}
}
name="active"
color="primary"
/>
)
}
}
}