mirror of
https://github.com/EnixCoda/Gitako.git
synced 2026-03-11 08:54:44 +00:00
14 lines
466 B
TypeScript
14 lines
466 B
TypeScript
import { useContext, useEffect } from 'react'
|
|
import { SidebarContext } from './SidebarContext'
|
|
|
|
export type FocusTarget = 'files' | 'search' | null
|
|
|
|
export function useFocusOnPendingTarget(target: FocusTarget, method: () => void) {
|
|
const { pendingFocusTarget } = useContext(SidebarContext)
|
|
useEffect(() => {
|
|
if (pendingFocusTarget.value === target) {
|
|
method()
|
|
pendingFocusTarget.onChange(null)
|
|
}
|
|
}, [target, method, pendingFocusTarget])
|
|
}
|