mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-06-04 06:39:02 +02:00
7f7556cf6a
Fix flicker when switching between editor and PDF views GitOrigin-RevId: 1f6543c0046dc458fa174aa9b54985934a7437fa
23 lines
665 B
TypeScript
23 lines
665 B
TypeScript
import { RefObject, useLayoutEffect } from 'react'
|
|
import { ImperativePanelHandle } from 'react-resizable-panels'
|
|
|
|
export default function useCollapsiblePanel(
|
|
panelIsOpen: boolean,
|
|
panelRef: RefObject<ImperativePanelHandle>
|
|
) {
|
|
// useLayoutEffect keeps the panel-size update in the same paint cycle as the
|
|
// CSS class changes that show/hide the panel content, eliminating a visible
|
|
// flash between the two changes.
|
|
useLayoutEffect(() => {
|
|
const panelHandle = panelRef.current
|
|
|
|
if (panelHandle) {
|
|
if (panelIsOpen) {
|
|
panelHandle.expand()
|
|
} else {
|
|
panelHandle.collapse()
|
|
}
|
|
}
|
|
}, [panelIsOpen, panelRef])
|
|
}
|