{"version":3,"file":"useEvent.mjs","sources":["../../../../../../../../web/src/ui/hooks/useEvent.ts"],"sourcesContent":["import { useCallback, useRef } from 'react';\n\nimport useIsomorphicLayoutEffect from './useIsomorphicLayoutEffect';\n\n/**\n * Use this for callbacks that are not called during render, most commonly event callbacks.\n * The returned callback will never change and therefore trigger unwanted effects\n * when used in deps or re-render of memoized components.\n * This is a copy of proposed the useEvent hook.\n */\nexport const useEvent = <Args extends unknown[], Ret = void>(fn: (...args: Args) => Ret) => {\n  const handlerRef = useRef(fn);\n  useIsomorphicLayoutEffect(() => {\n    handlerRef.current = fn;\n  }, [fn]);\n\n  return useCallback((...args: Args) => {\n    const fn = handlerRef.current;\n    return fn(...args);\n  }, []);\n};\n"],"names":["useEvent","fn","handlerRef","useRef","useIsomorphicLayoutEffect","current","useCallback","args"],"mappings":";;;;AAIA;;;;;IAMO,MAAMA,QAAAA,GAAW,CAAqCC,EAAAA,GAAAA;AAC3D,IAAA,MAAMC,aAAaC,CAAAA,CAAOF,EAAAA,CAAAA;IAC1BG,yBAAAA,CAA0B,IAAA;AACxBF,QAAAA,UAAAA,CAAWG,OAAO,GAAGJ,EAAAA;IACvB,CAAA,EAAG;AAACA,QAAAA;AAAG,KAAA,CAAA;IAEP,OAAOK,CAAAA,CAAY,CAAC,GAAGC,IAAAA,GAAAA;QACrB,MAAMN,EAAAA,GAAKC,WAAWG,OAAO;AAC7B,QAAA,OAAOJ,EAAAA,CAAAA,GAAMM,IAAAA,CAAAA;AACf,IAAA,CAAA,EAAG,EAAE,CAAA;AACP;;;;"}