const newAccounts = [...accounts]
const foundIndex = newAccounts.findIndex(x => x.id === id)
newAccounts[foundIndex] = newAccount
setAccounts(newAccounts)
update local state instead of update the cache
const [assignRole] = useMutation(MUTATION_ASSIGN_ROLE)
const handleSave = (id: string, role: string) => {
const assignRoleInput = { id, role }
assignRole({
variables: { assignRoleInput },
})
.then((data: any) => {
const newAccount = { ...data.data.assignRole }
const newAccounts = [...accounts]
const foundIndex = newAccounts.findIndex(x => x.id === id)
newAccounts[foundIndex] = newAccount
setAccounts(newAccounts)
})
.catch(error => console.log(error.message))
setOpenRolesDialog(false)
}
Comments
Post a Comment