mirror of
				https://github.com/khairul169/code-share.git
				synced 2025-10-31 03:39:34 +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;
 |