overleaf/services/web/frontend/js/features/ide-react/hooks/use-collapsible-panel.ts

18 lines
431 B
TypeScript
Raw Normal View History

import { RefObject, useEffect } from 'react'
import { ImperativePanelHandle } from 'react-resizable-panels'
export default function useCollapsiblePanel(
panelIsOpen: boolean,
panelRef: RefObject<ImperativePanelHandle>
) {
useEffect(() => {
if (panelRef.current) {
if (panelIsOpen) {
panelRef.current.expand()
} else {
panelRef.current.collapse()
}
}
}, [panelIsOpen, panelRef])
}