@@ -16,6 +16,7 @@ export const useSpace = (props: AllProps, divElementRef: React.MutableRefObject<
16
16
const parentContext = React . useContext ( SpaceContext ) ;
17
17
const layerContext = React . useContext ( SpaceLayerContext ) ;
18
18
const currentZIndex = props . zIndex || layerContext || 0 ;
19
+ const previouszIndex = usePrevious ( currentZIndex ) ;
19
20
20
21
// Deal with property changes to size / anchoring
21
22
React . useEffect ( ( ) => {
@@ -32,8 +33,11 @@ export const useSpace = (props: AllProps, divElementRef: React.MutableRefObject<
32
33
} )
33
34
if ( parentContext ) {
34
35
parentContext . updateSpaceTakerAdjustedSize ( state . id , 0 ) ;
36
+ if ( currentZIndex !== previouszIndex ) {
37
+ parentContext . updateSpaceTakerLayer ( state . id , currentZIndex ) ;
38
+ }
35
39
}
36
- } , [ props . zIndex , props . left , props . top , props . bottom , props . right , props . width , props . height , props . anchor , props . anchorSize , props . debug ] ) ;
40
+ } , [ currentZIndex , props . left , props . top , props . bottom , props . right , props . width , props . height , props . anchor , props . anchorSize , props . debug ] ) ;
37
41
38
42
// Setup / cleanup
39
43
React . useEffect ( ( ) => {
@@ -200,6 +204,20 @@ export const useSpace = (props: AllProps, divElementRef: React.MutableRefObject<
200
204
}
201
205
}
202
206
207
+ function usePrevious < T > ( value : T ) {
208
+ // The ref object is a generic container whose current property is mutable ...
209
+ // ... and can hold any value, similar to an instance property on a class
210
+ const ref = React . useRef < T > ( ) ;
211
+
212
+ // Store current value in ref
213
+ React . useEffect ( ( ) => {
214
+ ref . current = value ;
215
+ } , [ value ] ) ; // Only re-run if value changes
216
+
217
+ // Return previous value (happens before update in useEffect above)
218
+ return ref . current ;
219
+ }
220
+
203
221
export const useParentSpace = ( ) => {
204
222
const parentContext = React . useContext ( SpaceContext ) ;
205
223
0 commit comments