Skip to main content

useResolveIntent

The useResolveIntent hook completes the intent that your Mini is handling and sends the result back to the Shop app. Pair it with useIntent to read the incoming intent, then resolve it with an ok, error, or closed result.

Pass the intent key to useResolveIntent so TypeScript can narrow the result data to the intent's contract.

Anchor to intentKey
intentKey
K extends
required

<K extends >
Examples

tsx

import {useCallback} from 'react'

import {Button, useIntent, useResolveIntent} from '@shopify/shop-minis-react'

export default function TryOnResult() {
const {query} = useIntent()
const {resolveIntent} = useResolveIntent('tryOnProduct')

const handleUseImage = useCallback(async () => {
try {
await resolveIntent({
code: 'ok',
data: {imageUrl: 'https://cdn.shopify.com/tryon/example.jpg'},
})
} catch (resolveError) {
console.error('Could not resolve intent:', resolveError)
}
}, [resolveIntent])

const handleClose = useCallback(async () => {
try {
await resolveIntent({code: 'closed'})
} catch (resolveError) {
console.error('Could not close intent:', resolveError)
}
}, [resolveIntent])

if (!query) return null

if (query.action !== 'try_on' || query.type !== 'shopify/Product') {
return null
}

return (
<div>
<p>Use this image for {query.value ?? 'this product'}.</p>
<Button onClick={handleUseImage}>Use image</Button>
<Button onClick={handleClose} variant="secondary">
Cancel
</Button>
</div>
)
}


Was this page helpful?