1
1
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
2
// SPDX-License-Identifier: Apache-2.0
3
- import React , { FC , useLayoutEffect , useRef , useState } from 'react' ;
3
+ import React , { FC , MutableRefObject , useLayoutEffect , useRef , useState } from 'react' ;
4
4
5
5
import { AppLayoutProps } from '../interfaces' ;
6
6
import { AppLayoutVisibilityContext } from './contexts' ;
@@ -10,18 +10,21 @@ import { SkeletonLayout } from './skeleton';
10
10
import { useSkeletonSlotsAttributes } from './skeleton/widget-slots/use-skeleton-slots-attributes' ;
11
11
import { useAppLayout } from './use-app-layout' ;
12
12
13
+ type AppLayoutState = ReturnType < typeof useAppLayout > | null ;
14
+ type SkeletonSlotsAttributes = ReturnType < typeof useSkeletonSlotsAttributes > | null ;
15
+ interface StateManager {
16
+ set : ( appLayoutState : AppLayoutState , skeletonAttributes : SkeletonSlotsAttributes ) => void ;
17
+ }
18
+
13
19
const AppLayoutStateProvider : FC < {
14
- children : (
15
- appLayoutState : ReturnType < typeof useAppLayout > | null ,
16
- skeletonSlotsAttributes : ReturnType < typeof useSkeletonSlotsAttributes > | null
17
- ) => React . ReactNode ;
18
- stateManager : any ;
20
+ children : ( appLayoutState : AppLayoutState , skeletonSlotsAttributes : SkeletonSlotsAttributes ) => React . ReactNode ;
21
+ stateManager : MutableRefObject < StateManager > ;
19
22
} > = ( { stateManager, children } ) => {
20
- const [ appLayoutState , setAppLayoutState ] = useState ( null ) ;
21
- const [ skeletonAttributes , setSkeletonAttributes ] = useState ( null ) ;
23
+ const [ appLayoutState , setAppLayoutState ] = useState < AppLayoutState > ( null ) ;
24
+ const [ skeletonAttributes , setSkeletonAttributes ] = useState < SkeletonSlotsAttributes > ( null ) ;
22
25
23
26
useLayoutEffect ( ( ) => {
24
- stateManager . current . set = ( appLayoutState : any , skeletonAttributes : any ) => {
27
+ stateManager . current . set = ( appLayoutState , skeletonAttributes ) => {
25
28
setAppLayoutState ( appLayoutState ) ;
26
29
setSkeletonAttributes ( skeletonAttributes ) ;
27
30
} ;
@@ -31,7 +34,7 @@ const AppLayoutStateProvider: FC<{
31
34
32
35
const AppLayoutVisualRefreshToolbar = React . forwardRef < AppLayoutProps . Ref , AppLayoutInternalProps > (
33
36
( props , forwardRef ) => {
34
- const stateManager = useRef < any > ( { } ) ;
37
+ const stateManager = useRef < StateManager > ( { set : ( ) => { } } ) ;
35
38
36
39
return (
37
40
< >
0 commit comments