@@ -16,6 +16,7 @@ export const useSpace = (props: AllProps, divElementRef: React.MutableRefObject<
1616 const parentContext = React . useContext ( SpaceContext ) ;
1717 const layerContext = React . useContext ( SpaceLayerContext ) ;
1818 const currentZIndex = props . zIndex || layerContext || 0 ;
19+ const previouszIndex = usePrevious ( currentZIndex ) ;
1920
2021 // Deal with property changes to size / anchoring
2122 React . useEffect ( ( ) => {
@@ -32,8 +33,11 @@ export const useSpace = (props: AllProps, divElementRef: React.MutableRefObject<
3233 } )
3334 if ( parentContext ) {
3435 parentContext . updateSpaceTakerAdjustedSize ( state . id , 0 ) ;
36+ if ( currentZIndex !== previouszIndex ) {
37+ parentContext . updateSpaceTakerLayer ( state . id , currentZIndex ) ;
38+ }
3539 }
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 ] ) ;
3741
3842 // Setup / cleanup
3943 React . useEffect ( ( ) => {
@@ -200,6 +204,20 @@ export const useSpace = (props: AllProps, divElementRef: React.MutableRefObject<
200204 }
201205}
202206
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+
203221export const useParentSpace = ( ) => {
204222 const parentContext = React . useContext ( SpaceContext ) ;
205223
0 commit comments