Skip to content

Commit 1ef115b

Browse files
authored
Merge pull request Expensify#68736 from software-mansion-labs/fix/remove-nav-console-error
Adjust useSyncSidePanelWithHistory to call dispatch when nav is ready
2 parents aa57be5 + 8a20819 commit 1ef115b

1 file changed

Lines changed: 12 additions & 8 deletions

File tree

  • src/components/SidePanel/useSyncSidePanelWithHistory

src/components/SidePanel/useSyncSidePanelWithHistory/index.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,19 @@ import {useEffect} from 'react';
33
import usePrevious from '@hooks/usePrevious';
44
import useResponsiveLayout from '@hooks/useResponsiveLayout';
55
import useSidePanel from '@hooks/useSidePanel';
6+
import Navigation from '@libs/Navigation/Navigation';
67
import navigationRef from '@libs/Navigation/navigationRef';
78
import CONST from '@src/CONST';
89

10+
function toggleSidePanelWithHistory(isVisible: boolean) {
11+
Navigation.isNavigationReady().then(() => {
12+
navigationRef.dispatch({
13+
type: CONST.NAVIGATION.ACTION_TYPE.TOGGLE_SIDE_PANEL_WITH_HISTORY,
14+
payload: {isVisible},
15+
});
16+
});
17+
}
18+
919
export default function useSyncSidePanelWithHistory() {
1020
const {closeSidePanel, openSidePanel, shouldHideSidePanel} = useSidePanel();
1121
const {isExtraLargeScreenWidth} = useResponsiveLayout();
@@ -16,18 +26,12 @@ export default function useSyncSidePanelWithHistory() {
1626
// If the window width has been expanded and the modal is displayed, remove its history entry.
1727
// The side panel is only synced with the history when it's displayed as RHP.
1828
if (!shouldHideSidePanel && isExtraLargeScreenWidth) {
19-
navigationRef.dispatch({
20-
type: CONST.NAVIGATION.ACTION_TYPE.TOGGLE_SIDE_PANEL_WITH_HISTORY,
21-
payload: {isVisible: false},
22-
});
29+
toggleSidePanelWithHistory(false);
2330
return;
2431
}
2532

2633
// When shouldHideSidePanel changes, synchronize the side panel with the browser history.
27-
navigationRef.dispatch({
28-
type: CONST.NAVIGATION.ACTION_TYPE.TOGGLE_SIDE_PANEL_WITH_HISTORY,
29-
payload: {isVisible: !shouldHideSidePanel},
30-
});
34+
toggleSidePanelWithHistory(!shouldHideSidePanel);
3135
}, [shouldHideSidePanel, isExtraLargeScreenWidth]);
3236

3337
useEffect(() => {

0 commit comments

Comments
 (0)