@@ -41,7 +41,7 @@ export const usePopper = (
41
41
const [ state , setState ] = React . useState < State > ( {
42
42
styles : {
43
43
popper : {
44
- position : optionsWithDefaults . strategy || 'absolute' ,
44
+ position : optionsWithDefaults . strategy ,
45
45
left : '0' ,
46
46
top : '0' ,
47
47
} ,
@@ -68,14 +68,14 @@ export const usePopper = (
68
68
} ,
69
69
requires : [ 'computeStyles' ] ,
70
70
} ) ,
71
- [ setState ]
71
+ [ ]
72
72
) ;
73
73
74
74
const popperOptions = React . useMemo ( ( ) => {
75
75
const newOptions = {
76
76
onFirstUpdate : optionsWithDefaults . onFirstUpdate ,
77
- placement : optionsWithDefaults . placement || 'bottom' ,
78
- strategy : optionsWithDefaults . strategy || 'absolute' ,
77
+ placement : optionsWithDefaults . placement ,
78
+ strategy : optionsWithDefaults . strategy ,
79
79
modifiers : [
80
80
...optionsWithDefaults . modifiers ,
81
81
updateStateModifier ,
@@ -98,35 +98,32 @@ export const usePopper = (
98
98
] ) ;
99
99
100
100
const popperInstanceRef = React . useRef ( ) ;
101
- const createPopper = React . useMemo (
102
- ( ) => options . createPopper || defaultCreatePopper ,
103
- [ options . createPopper ]
104
- ) ;
105
101
106
102
useIsomorphicLayoutEffect ( ( ) => {
107
- let popperInstance = null ;
108
- if ( referenceElement != null && popperElement != null ) {
109
- popperInstance = createPopper (
110
- referenceElement ,
111
- popperElement ,
112
- popperOptions
113
- ) ;
114
-
115
- popperInstanceRef . current = popperInstance ;
103
+ if ( popperInstanceRef . current ) {
104
+ popperInstanceRef . current . setOptions ( popperOptions ) ;
105
+ }
106
+ } , [ popperOptions ] ) ;
107
+
108
+ useIsomorphicLayoutEffect ( ( ) => {
109
+ if ( referenceElement == null || popperElement == null ) {
110
+ return ;
116
111
}
117
112
113
+ const createPopper = options . createPopper || defaultCreatePopper ;
114
+ const popperInstance = createPopper (
115
+ referenceElement ,
116
+ popperElement ,
117
+ popperOptions
118
+ ) ;
119
+
120
+ popperInstanceRef . current = popperInstance ;
121
+
118
122
return ( ) => {
119
- popperInstance != null && popperInstance . destroy ( ) ;
123
+ popperInstance . destroy ( ) ;
120
124
popperInstanceRef . current = null ;
121
125
} ;
122
- // eslint-disable-next-line react-hooks/exhaustive-deps
123
- } , [ referenceElement , popperElement , createPopper ] ) ;
124
-
125
- useIsomorphicLayoutEffect ( ( ) => {
126
- if ( popperInstanceRef . current ) {
127
- popperInstanceRef . current . setOptions ( popperOptions ) ;
128
- }
129
- } , [ popperOptions ] ) ;
126
+ } , [ referenceElement , popperElement , options . createPopper ] ) ;
130
127
131
128
return {
132
129
state : popperInstanceRef . current ? popperInstanceRef . current . state : null ,
0 commit comments