diff --git a/src/index.tsx b/src/index.tsx index 0b1fb77..914cd6c 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -127,6 +127,17 @@ const Toast = (props: ToastProps) => { setMounted(true); }, []); + React.useEffect(() => { + const toastNode = toastRef.current; + if (toastNode) { + const height = toastNode.getBoundingClientRect().height; + // Add toast height tot heights array after the toast is mounted + setInitialHeight(height); + setHeights((h) => [{ toastId: toast.id, height, position: toast.position }, ...h]); + return () => setHeights((h) => h.filter((height) => height.toastId !== toast.id)); + } + }, [setHeights, toast.id]); + React.useLayoutEffect(() => { if (!mounted) return; const toastNode = toastRef.current; @@ -219,7 +230,10 @@ const Toast = (props: ToastProps) => { function getLoadingIcon() { if (icons?.loading) { return ( -