From b14d69aca3a557989f5283c294594ac474695df8 Mon Sep 17 00:00:00 2001 From: Herway Date: Fri, 27 Dec 2024 13:47:16 +0800 Subject: [PATCH] fix: inability to update toast duration dynamically #529 Inability to update toast duration dynamically closed #529 --- src/index.tsx | 4 ++++ test/src/app/page.tsx | 17 +++++++++++++++++ test/tests/basic.spec.ts | 16 ++++++++++++++++ 3 files changed, 37 insertions(+) diff --git a/src/index.tsx b/src/index.tsx index a3ea512..d831bdf 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -124,6 +124,10 @@ const Toast = (props: ToastProps) => { offset.current = React.useMemo(() => heightIndex * gap + toastsHeightBefore, [heightIndex, toastsHeightBefore]); + React.useEffect(() => { + remainingTime.current = duration; + }, [duration]); + React.useEffect(() => { // Trigger enter animation without using CSS animation setMounted(true); diff --git a/test/src/app/page.tsx b/test/src/app/page.tsx index 6730447..83db7d4 100644 --- a/test/src/app/page.tsx +++ b/test/src/app/page.tsx @@ -171,6 +171,23 @@ export default function Home({ searchParams }: any) { > Updated Toast +