UNPKG

@shopify/shop-minis-react

Version:

React component library for Shopify Shop Minis with Tailwind CSS v4 support (source-only, requires TypeScript)

25 lines (20 loc) 618 B
import {useCallback} from 'react' import {ShopActionResult} from '../types' // Wrapper to handle shop action results as regular promises (Reject on error) export const useHandleAction = <T, Args extends unknown[]>( action: (...args: Args) => Promise<ShopActionResult<T>> ) => { // TODO Add when report interaction is implemented for web // const reportInteraction = useReportInteraction() return useCallback( (...args: Args) => { return action(...args).then(result => { if (result.ok) { return result.data } throw result.error }) }, [action] ) }