Skip to content

Commit 2476619

Browse files
committed
declare interval at higher level to prvent memory issues
1 parent e4dbdea commit 2476619

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

packages/ui-components/src/hooks/use-typing-animation.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export function useTypingAnimation({
1818
const prevIsDefaultRef = useRef(isDefault);
1919

2020
useEffect(() => {
21+
let interval: NodeJS.Timeout | undefined;
2122
const shouldAnimate =
2223
prevChatIdRef.current === chatId &&
2324
prevIsDefaultRef.current === true &&
@@ -26,7 +27,7 @@ export function useTypingAnimation({
2627
if (shouldAnimate && text.length > 0) {
2728
setDisplayedText('');
2829
let currentIndex = 0;
29-
const interval = setInterval(() => {
30+
interval = setInterval(() => {
3031
if (currentIndex < text.length) {
3132
setDisplayedText(text.slice(0, currentIndex + 1));
3233
currentIndex++;

0 commit comments

Comments
 (0)