overleaf/services/web/frontend/js/shared/hooks/use-scope-event-emitter.ts
ilkin-overleaf d959dbc236 Merge pull request #11105 from overleaf/ii-shared-hooks-js-to-ts-conversion
[web] Shared React hooks JS to TS conversion

GitOrigin-RevId: 0ccdebff236c7424b1a73cd7d6646a9d01a20eb1
2023-01-10 09:05:52 +00:00

20 lines
459 B
TypeScript

import { useCallback } from 'react'
import { useIdeContext } from '../context/ide-context'
export default function useScopeEventEmitter(
eventName: string,
broadcast = true
) {
const { $scope } = useIdeContext()
return useCallback(
(...detail: unknown[]) => {
if (broadcast) {
$scope.$broadcast(eventName, ...detail)
} else {
$scope.$emit(eventName, ...detail)
}
},
[$scope, eventName, broadcast]
)
}