Add image component for editor (#57)
* Add image component * More image editor * add more image changes
This commit is contained in:
16
packages/email-editor/src/hooks/useEvent.ts
Normal file
16
packages/email-editor/src/hooks/useEvent.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import { useCallback, useLayoutEffect, useRef } from "react";
|
||||
|
||||
export const useEvent = <T extends (...args: any[]) => any>(handler: T): T => {
|
||||
const handlerRef = useRef<T | null>(null);
|
||||
|
||||
useLayoutEffect(() => {
|
||||
handlerRef.current = handler;
|
||||
}, [handler]);
|
||||
|
||||
return useCallback((...args: Parameters<T>): ReturnType<T> => {
|
||||
if (handlerRef.current === null) {
|
||||
throw new Error("Handler is not assigned");
|
||||
}
|
||||
return handlerRef.current(...args);
|
||||
}, []) as T;
|
||||
};
|
Reference in New Issue
Block a user