I'm trying to run the following script that sets a temporary state based on a selected table row, and then immediately uses that state for a REST Api. I'm not passing in the table data directly because it's possible for the user to still select rows in the background with the modal open (I'm still using this variable beyond the query), meaning I cannot rely on the selected row to be accurate, and there's no method to disable row selection.
On the first run when the capturedCompanyId
temporary state is null, the deleteCompany
is triggered while it's still null.
I tried awaiting the setValue
command, that id nothing so then I tried then
-ning it, and that still does nothing.
capturedCompanyId.setValue(Companies_Table.selectedRow.id).then(
deleteCompany.trigger({
additionalScope: {
companyId: capturedCompanyId.value,
dryRun: true
},
onSuccess:(data) => {
console.log(data, 'onSuccess')
},
onFailure: (data) =>{
console.log(data, 'onFailure')
if (deleteCompany.data.data.error === "PROTECTED_ITEM") {
console.log('protected item')
}
},
}))
I'm not sure how we're supposed to use temporary states if we can't wait for their values to finish applying before using them. Are there any workarounds? I need to lock in the id property of the selected row once the user opens the modal.