refactor
This commit is contained in:
@@ -1,8 +1,6 @@
|
||||
import React, {
|
||||
ReactNode,
|
||||
createContext,
|
||||
useCallback,
|
||||
useContext,
|
||||
useEffect,
|
||||
useMemo,
|
||||
useRef,
|
||||
@@ -20,6 +18,7 @@ import {
|
||||
SIDEBAR_SOLO_THRESHOLD,
|
||||
type PanelKey,
|
||||
} from '../constants/layout';
|
||||
import { createSafeContext } from '../utils/createSafeContext';
|
||||
|
||||
interface SetPanelWidthOptions {
|
||||
commit?: boolean;
|
||||
@@ -51,7 +50,7 @@ type PanelResizeBindings = {
|
||||
isPanelResizing: boolean;
|
||||
};
|
||||
|
||||
const PanelManagerContext = createContext<PanelManagerContextValue | null>(null);
|
||||
const [PanelManagerContext, usePanelManager] = createSafeContext<PanelManagerContextValue>('PanelManager');
|
||||
|
||||
const clampPanelWidth = (panel: PanelKey, value: number): number => {
|
||||
const numeric = Number(value);
|
||||
@@ -307,13 +306,7 @@ export const PanelManagerProvider: React.FC<PanelManagerProviderProps> = ({ chil
|
||||
return <PanelManagerContext.Provider value={contextValue}>{children}</PanelManagerContext.Provider>;
|
||||
};
|
||||
|
||||
export const usePanelManager = () => {
|
||||
const context = useContext(PanelManagerContext);
|
||||
if (!context) {
|
||||
throw new Error('usePanelManager must be used within a PanelManagerProvider');
|
||||
}
|
||||
return context;
|
||||
};
|
||||
export { usePanelManager };
|
||||
|
||||
export const usePanelResizeBindings = (
|
||||
panel: PanelKey,
|
||||
|
||||
Reference in New Issue
Block a user