refactoring useUndoRedo component

This commit is contained in:
2025-10-27 16:10:47 +05:30
parent 8a4d677b02
commit a7ead0d8d1
5 changed files with 33 additions and 15 deletions

View File

@@ -0,0 +1,26 @@
import { createContext, useContext } from "react";
export type UndoRedoAction = {
undo: () => void;
do: () => void;
};
export type UndoRedoContextType = {
addAction: (action: UndoRedoAction) => void;
undo: () => void;
redo: () => void;
canUndo: boolean;
canRedo: boolean;
stackCount: { undo: number; redo: number };
setShortcutKeys?: (undoKey?: string, redoKey?: string) => void;
};
export const UndoRedoContext = createContext<UndoRedoContextType | null>(null);
export const useUndoRedo = () => {
const ctx = useContext(UndoRedoContext);
if (!ctx) {
throw new Error("useUndoRedo must be used inside an UndoRedoProvider");
}
return ctx;
};