mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
d959dbc236
[web] Shared React hooks JS to TS conversion GitOrigin-RevId: 0ccdebff236c7424b1a73cd7d6646a9d01a20eb1
20 lines
459 B
TypeScript
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]
|
|
)
|
|
}
|