mirror of
https://github.com/khairul169/code-share.git
synced 2025-04-28 16:49:36 +07:00
22 lines
554 B
TypeScript
22 lines
554 B
TypeScript
import type { FileSchema } from "~/server/db/schema/file";
|
|
import { createContext, useContext } from "react";
|
|
|
|
type TEditorContext = {
|
|
onOpenFile: (fileId: number) => void;
|
|
onFileChanged: (file: Omit<FileSchema, "content">) => void;
|
|
onDeleteFile: (fileId: number) => void;
|
|
};
|
|
|
|
const EditorContext = createContext<TEditorContext | null>(null);
|
|
|
|
export const useEditorContext = () => {
|
|
const ctx = useContext(EditorContext);
|
|
if (!ctx) {
|
|
throw new Error("Component not in EditorContext!");
|
|
}
|
|
|
|
return ctx;
|
|
};
|
|
|
|
export default EditorContext;
|