UNPKG

@shopify/shop-minis-react

Version:

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

17 lines (13 loc) 519 B
import {useEffect, useRef} from 'react' export function useOnMiniBlur(callback: () => void) { // Using a ref allows the callback to be updated without triggering a re-render // This makes the hook nicer to use because developers don't need useCallback const callbackRef = useRef(callback) callbackRef.current = callback useEffect(() => { const listenerId = window.minisEvents.on('MINI_APP_BLUR', () => { callbackRef.current() }) return () => window.minisEvents.off(listenerId) }, []) }