mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-09-21 00:10:33 +02:00
feat: command palette (#7804)
Co-authored-by: dwelle <5153846+dwelle@users.noreply.github.com>
This commit is contained in:
18
packages/excalidraw/hooks/useStableCallback.ts
Normal file
18
packages/excalidraw/hooks/useStableCallback.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import { useRef } from "react";
|
||||
|
||||
/**
|
||||
* Returns a stable function of the same type.
|
||||
*/
|
||||
export const useStableCallback = <T extends (...args: any[]) => any>(
|
||||
userFn: T,
|
||||
) => {
|
||||
const stableRef = useRef<{ userFn: T; stableFn?: T }>({ userFn });
|
||||
stableRef.current.userFn = userFn;
|
||||
|
||||
if (!stableRef.current.stableFn) {
|
||||
stableRef.current.stableFn = ((...args: any[]) =>
|
||||
stableRef.current.userFn(...args)) as T;
|
||||
}
|
||||
|
||||
return stableRef.current.stableFn as T;
|
||||
};
|
Reference in New Issue
Block a user