nit: fix perf regression in hotkeys (#10302)
Co-authored-by: Samuel Newman <mozzius@protonmail.com>
This commit is contained in:
@@ -1,10 +1,17 @@
|
|||||||
|
import {useMemo} from 'react'
|
||||||
|
|
||||||
export function Provider({children}: {children: React.ReactNode}) {
|
export function Provider({children}: {children: React.ReactNode}) {
|
||||||
return children
|
return children
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const noop = () => {}
|
||||||
|
|
||||||
export function useHotkeysContext() {
|
export function useHotkeysContext() {
|
||||||
return {
|
return useMemo(
|
||||||
enableScope: () => {},
|
() => ({
|
||||||
disableScope: () => {},
|
enableScope: noop,
|
||||||
}
|
disableScope: noop,
|
||||||
|
}),
|
||||||
|
[],
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import {createContext, useContext, useState} from 'react'
|
import {createContext, useCallback, useContext, useState} from 'react'
|
||||||
|
|
||||||
import {useHotkeysContext} from '#/lib/hotkeys'
|
import {useHotkeysContext} from '#/lib/hotkeys'
|
||||||
|
|
||||||
@@ -14,14 +14,17 @@ export function Provider({children}: React.PropsWithChildren<{}>) {
|
|||||||
const [state, setState] = useState(false)
|
const [state, setState] = useState(false)
|
||||||
const {disableScope, enableScope} = useHotkeysContext()
|
const {disableScope, enableScope} = useHotkeysContext()
|
||||||
|
|
||||||
const setDrawerOpen = (open: boolean) => {
|
const setDrawerOpen = useCallback(
|
||||||
|
(open: boolean) => {
|
||||||
if (open) {
|
if (open) {
|
||||||
disableScope('global')
|
disableScope('global')
|
||||||
} else {
|
} else {
|
||||||
enableScope('global')
|
enableScope('global')
|
||||||
}
|
}
|
||||||
setState(open)
|
setState(open)
|
||||||
}
|
},
|
||||||
|
[disableScope, enableScope],
|
||||||
|
)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<stateContext.Provider value={state}>
|
<stateContext.Provider value={state}>
|
||||||
|
|||||||
Reference in New Issue
Block a user