Development discussions around Shopify APIs
I have code to delete some items from the table but the selection will not update. How do I trigger a recalculation of selectedResources from useIndexResourceState?
Can you please tell me if you have figured it out?
This is what I did:
Hi @belazaras. How are you today?
I'm Olavo from Shopify. Thank you for reaching out.
If I understood correctly, you're using an `IndexTable` and deleting multiple selected entries but the `selectedResources` from `useIndexResourceState` isn't reflecting all changes, correct?
If so, an easy way to get around this is to trigger the `handleSelectionChange` function with a deselect action once you deleted your entries. If you look at the code for this hook you'll see that the `handleSelectionChange` function expects the `SelectionType` (which is an enum) and a boolean (that represents if this action is selecting or de-selecting items). So, if you want to deselect everything, you'd call it with `handleSelectionChange(SelectionType.All, false)` (because you don't have access to enum you can just write `"all"`).
In practice you'd have something in the lines of:
function onDelete(items) {
// ... Your logic to delete the items ...
handleSelectionChange('all', false) // <~~ This will trigger the recalculation
}
I hope this helps. Let me know if you have any more questions.
User | RANK |
---|---|
8 | |
7 | |
3 | |
3 | |
3 |
Connect your PayPal account to allow your customers to checkout using the PayPal gateway a...
ByYour online store speed can enhance your store’s discoverability, boost conversion rates a...
ByShopping is at our fingertips with mobile devices. Is your theme optimized to be user-frie...
By