Shop events
Sometimes we want to subscribe to an event that occurs within the Shop app to execute a callback function. The Minis SDK provides a few React hooks for doing so.
On successful checkout
We can use the useCheckoutSuccessfully()
hook to subscribe to when a checkout is successful. The callback function is called with an order GID.
import {useCheckoutSuccessfully} from '@shopify/shop-minis-platform-sdk/events'
// ...
useCheckoutSuccessfully(orderId => {
console.log(orderId)
})
On product variant updated
We can use the useOnVariantUpdated()
hook to subscribe to when a new product variant is selected. The callback function is called with the product variant object.
import {useOnVariantUpdated} from '@shopify/shop-minis-platform-sdk/events'
// ...
useOnVariantUpdated(variant => {
console.log(variant)
})
On Mini app closed
We can use the useOnMiniAppClosed()
hook to subscribe to when the buyer closes the Mini Viewer.
import {useOnMiniAppClosed} from '@shopify/shop-minis-platform-sdk/events'
// ...
useOnMiniAppClosed(() => {
console.log('Mini app closed.')
})