Ensure that all callbacks for useEventListener are wrapped in useCallback (#22618)

GitOrigin-RevId: 4a7c409a9720eab04fc17e5111b6a3aeeac6871d
This commit is contained in:
Alf Eaton
2025-01-09 09:05:00 +00:00
committed by Copybot
parent 49cc7890e4
commit aaeac2cd72
4 changed files with 40 additions and 18 deletions
@@ -1,12 +1,19 @@
import useEventListener from '@/shared/hooks/use-event-listener'
import { useLocalCompileContext } from '@/shared/context/local-compile-context'
import { useCallback } from 'react'
export function useHasLintingError() {
const { setHasLintingError } = useLocalCompileContext()
// Listen for editor:lint event from CM6 linter and keep compile context
// up to date
useEventListener('editor:lint', (event: CustomEvent) => {
setHasLintingError(event.detail.hasLintingError)
})
useEventListener(
'editor:lint',
useCallback(
(event: CustomEvent) => {
setHasLintingError(event.detail.hasLintingError)
},
[setHasLintingError]
)
)
}