File tree Expand file tree Collapse file tree 2 files changed +11
-3
lines changed
packages/@react-aria/utils/src Expand file tree Collapse file tree 2 files changed +11
-3
lines changed Original file line number Diff line number Diff line change @@ -17,7 +17,10 @@ import {useLayoutEffect} from './useLayoutEffect';
1717// before all layout effects, but is available only in React 18 and later.
1818const useEarlyEffect = React [ 'useInsertionEffect' ] ?? useLayoutEffect ;
1919
20- export function useEffectEvent < T extends Function > ( fn ?: T ) : T {
20+ // Starting with React 19.2, this hook has been internalized.
21+ const useModernEffectEvent = React [ 'useEffectEvent' ] ?? useLegacyEffectEvent ;
22+
23+ function useLegacyEffectEvent < T extends Function > ( fn ?: T ) : T {
2124 const ref = useRef < T | null | undefined > ( null ) ;
2225 useEarlyEffect ( ( ) => {
2326 ref . current = fn ;
@@ -28,3 +31,7 @@ export function useEffectEvent<T extends Function>(fn?: T): T {
2831 return f ?.( ...args ) ;
2932 } , [ ] ) ;
3033}
34+
35+ export function useEffectEvent < T extends Function > ( fn : T ) : T {
36+ return useModernEffectEvent ( fn ) ;
37+ }
Original file line number Diff line number Diff line change 1111 */
1212
1313import { RefObject } from '@react-types/shared' ;
14- import { useEffect } from 'react' ;
14+ import { useCallback , useEffect } from 'react' ;
1515import { useEffectEvent } from './useEffectEvent' ;
1616
1717export function useEvent < K extends keyof GlobalEventHandlersEventMap > (
@@ -20,7 +20,8 @@ export function useEvent<K extends keyof GlobalEventHandlersEventMap>(
2020 handler ?: ( this : Document , ev : GlobalEventHandlersEventMap [ K ] ) => any ,
2121 options ?: boolean | AddEventListenerOptions
2222) : void {
23- let handleEvent = useEffectEvent ( handler ) ;
23+ let noop = useCallback ( ( ) => { } , [ ] ) ;
24+ let handleEvent = useEffectEvent ( handler ?? noop ) ;
2425 let isDisabled = handler == null ;
2526
2627 useEffect ( ( ) => {
You can’t perform that action at this time.
0 commit comments