feat: budget crud actions
This commit is contained in:
@@ -1,14 +1,18 @@
|
||||
import { useEffect, useRef } from "react";
|
||||
import { keysStore } from "./store";
|
||||
import type { Key } from "./types";
|
||||
import { enforceKeyOptions } from "./util";
|
||||
|
||||
export const useShortcut = (key: string, handler: () => void) => {
|
||||
export const useShortcut = (key: Key, handler: () => void) => {
|
||||
const keyOptions = enforceKeyOptions(key);
|
||||
const keyName = keyOptions.name;
|
||||
const ref = useRef(handler);
|
||||
ref.current = handler;
|
||||
|
||||
useEffect(() => {
|
||||
keysStore.register(key, ref);
|
||||
keysStore.register(keyName, ref);
|
||||
return () => {
|
||||
keysStore.deregister(key);
|
||||
keysStore.deregister(keyName);
|
||||
};
|
||||
}, []);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user