Skip to content

Commit 84e08ba

Browse files
committed
chore: Types for a state manager
1 parent 02e3f9c commit 84e08ba

File tree

2 files changed

+22
-12
lines changed

2 files changed

+22
-12
lines changed

src/app-layout/visual-refresh-toolbar/app-layout-state.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,24 @@
11
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
// SPDX-License-Identifier: Apache-2.0
3-
import React, { ForwardedRef, useLayoutEffect } from 'react';
3+
import React, { ForwardedRef, MutableRefObject, useLayoutEffect } from 'react';
44

55
import { createWidgetizedComponent } from '../../internal/widgets';
66
import { AppLayoutProps } from '../interfaces';
77
import { AppLayoutInternalProps } from './interfaces';
88
import { useSkeletonSlotsAttributes } from './skeleton/widget-slots/use-skeleton-slots-attributes';
99
import { useAppLayout } from './use-app-layout';
1010

11+
interface StateManager {
12+
set: (
13+
appLayoutState: ReturnType<typeof useAppLayout> | null,
14+
skeletonAttributes: ReturnType<typeof useSkeletonSlotsAttributes> | null
15+
) => void;
16+
}
17+
1118
export interface AppLayoutStateProps {
1219
props: AppLayoutInternalProps;
1320
forwardRef: ForwardedRef<AppLayoutProps.Ref>;
14-
stateManager: any;
21+
stateManager: MutableRefObject<StateManager>;
1522
}
1623

1724
export const AppLayoutState = (props: AppLayoutStateProps) => {

src/app-layout/visual-refresh-toolbar/index.tsx

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
// 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';
44

55
import { AppLayoutProps } from '../interfaces';
66
import { AppLayoutVisibilityContext } from './contexts';
@@ -10,18 +10,21 @@ import { SkeletonLayout } from './skeleton';
1010
import { useSkeletonSlotsAttributes } from './skeleton/widget-slots/use-skeleton-slots-attributes';
1111
import { useAppLayout } from './use-app-layout';
1212

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+
1319
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>;
1922
}> = ({ 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);
2225

2326
useLayoutEffect(() => {
24-
stateManager.current.set = (appLayoutState: any, skeletonAttributes: any) => {
27+
stateManager.current.set = (appLayoutState, skeletonAttributes) => {
2528
setAppLayoutState(appLayoutState);
2629
setSkeletonAttributes(skeletonAttributes);
2730
};
@@ -31,7 +34,7 @@ const AppLayoutStateProvider: FC<{
3134

3235
const AppLayoutVisualRefreshToolbar = React.forwardRef<AppLayoutProps.Ref, AppLayoutInternalProps>(
3336
(props, forwardRef) => {
34-
const stateManager = useRef<any>({});
37+
const stateManager = useRef<StateManager>({ set: () => {} });
3538

3639
return (
3740
<>

0 commit comments

Comments
 (0)