File tree Expand file tree Collapse file tree 1 file changed +5
-4
lines changed Expand file tree Collapse file tree 1 file changed +5
-4
lines changed Original file line number Diff line number Diff line change 1
1
/* eslint-disable @typescript-eslint/explicit-function-return-type */
2
2
import { useCallback , useInsertionEffect , useRef } from 'react' ;
3
+ import { useIsomorphicLayoutEffect } from './useIsomorphicLayoutEffect' ;
4
+
5
+ const useInsertionEffectFallback = useInsertionEffect || useIsomorphicLayoutEffect ;
3
6
4
7
/**
5
8
* This hook is user-land implementation of the experimental `useEffectEvent` hook.
@@ -11,11 +14,9 @@ function useCallbackRef<Args extends unknown[], Return>(
11
14
callback : ( ( ...args : Args ) => Return ) | undefined ,
12
15
deps : React . DependencyList = [ ] ,
13
16
) {
14
- const callbackRef = useRef < typeof callback > ( ( ) => {
15
- throw new Error ( 'Cannot call an event handler while rendering.' ) ;
16
- } ) ;
17
+ const callbackRef = useRef < typeof callback > ( callback ) ;
17
18
18
- useInsertionEffect ( ( ) => {
19
+ useInsertionEffectFallback ( ( ) => {
19
20
callbackRef . current = callback ;
20
21
} ) ;
21
22
You can’t perform that action at this time.
0 commit comments