-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #34861 from tienifr/fix/32753
Fix: User navigates to many pages when quickly press them
- Loading branch information
Showing
3 changed files
with
66 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import React, {createContext, useMemo} from 'react'; | ||
import useSingleExecution from '@hooks/useSingleExecution'; | ||
import type {Action} from '@hooks/useSingleExecution'; | ||
import useWaitForNavigation from '@hooks/useWaitForNavigation'; | ||
|
||
type MenuItemGroupContextProps = { | ||
isExecuting: boolean; | ||
singleExecution: <T extends unknown[]>(action?: Action<T> | undefined) => (...params: T) => void; | ||
waitForNavigate: ReturnType<typeof useWaitForNavigation>; | ||
}; | ||
|
||
const MenuItemGroupContext = createContext<MenuItemGroupContextProps | undefined>(undefined); | ||
|
||
type MenuItemGroupProps = { | ||
/* Actual content wrapped by this component */ | ||
children: React.ReactNode; | ||
|
||
/** Whether or not to use the single execution hook */ | ||
shouldUseSingleExecution?: boolean; | ||
}; | ||
|
||
function MenuItemGroup({children, shouldUseSingleExecution = true}: MenuItemGroupProps) { | ||
const {isExecuting, singleExecution} = useSingleExecution(); | ||
const waitForNavigate = useWaitForNavigation(); | ||
|
||
const value = useMemo( | ||
() => (shouldUseSingleExecution ? {isExecuting, singleExecution, waitForNavigate} : undefined), | ||
[shouldUseSingleExecution, isExecuting, singleExecution, waitForNavigate], | ||
); | ||
|
||
return <MenuItemGroupContext.Provider value={value}>{children}</MenuItemGroupContext.Provider>; | ||
} | ||
|
||
export {MenuItemGroupContext}; | ||
export default MenuItemGroup; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters