mirror of
https://github.com/spacedriveapp/spacedrive.git
synced 2026-04-28 02:18:01 -04:00
27 lines
700 B
TypeScript
27 lines
700 B
TypeScript
import { createContext, PropsWithChildren, useContext, useState } from 'react';
|
|
|
|
interface QuickPreviewContext {
|
|
ref: HTMLDivElement | null;
|
|
}
|
|
|
|
const QuickPreviewContext = createContext<QuickPreviewContext | null>(null);
|
|
|
|
export const QuickPreviewContextProvider = ({ children }: PropsWithChildren) => {
|
|
const [ref, setRef] = useState<HTMLDivElement | null>(null);
|
|
|
|
return (
|
|
<QuickPreviewContext.Provider value={{ ref }}>
|
|
{children}
|
|
<div ref={setRef} />
|
|
</QuickPreviewContext.Provider>
|
|
);
|
|
};
|
|
|
|
export const useQuickPreviewContext = () => {
|
|
const context = useContext(QuickPreviewContext);
|
|
|
|
if (!context) throw new Error('QuickPreviewContext.Provider not found!');
|
|
|
|
return context;
|
|
};
|