refactor
This commit is contained in:
@@ -1,22 +1,15 @@
|
||||
import React, { createContext, useContext, useState, useCallback, useMemo, useRef } from 'react';
|
||||
import React, { useState, useCallback, useMemo, useRef } from 'react';
|
||||
import PreviewZoomOverlay from '../detail/PreviewZoomOverlay';
|
||||
import type { Document } from '../types/documents';
|
||||
import type { Identifier } from '../types/identifiers';
|
||||
import { createSafeContext } from '../utils/createSafeContext';
|
||||
|
||||
interface PreviewContextType {
|
||||
openPreview: (doc: Document) => void;
|
||||
closePreview: () => void;
|
||||
}
|
||||
|
||||
const PreviewContext = createContext<PreviewContextType | null>(null);
|
||||
|
||||
export const usePreviewContext = () => {
|
||||
const context = useContext(PreviewContext);
|
||||
if (!context) {
|
||||
throw new Error('usePreviewContext must be used within a PreviewProvider');
|
||||
}
|
||||
return context;
|
||||
};
|
||||
const [PreviewContext, usePreviewContext] = createSafeContext<PreviewContextType>('Preview');
|
||||
|
||||
interface PreviewProviderProps {
|
||||
children: React.ReactNode;
|
||||
@@ -66,3 +59,5 @@ export const PreviewProvider: React.FC<PreviewProviderProps> = ({ children, onNa
|
||||
</PreviewContext.Provider>
|
||||
);
|
||||
};
|
||||
|
||||
export { usePreviewContext };
|
||||
|
||||
Reference in New Issue
Block a user