The Open Standard for Generative UI
fix scroll to bottom (#93)
abhithesys9de6c0fe341a
diff --git a/js/packages/react-ui/package.json b/js/packages/react-ui/package.jsonindex 59914420e..c267f53d2 100644--- a/js/packages/react-ui/package.json+++ b/js/packages/react-ui/package.json@@ -2,7 +2,7 @@"type": "module","name": "@crayonai/react-ui","license": "MIT",- "version": "0.6.2",+ "version": "0.6.3","description": "Component library for Generative UI SDK","main": "dist/index.js","types": "dist/index.d.ts",diff --git a/js/packages/react-ui/src/hooks/useScrollToBottom.ts b/js/packages/react-ui/src/hooks/useScrollToBottom.tsindex dab1119c2..4456dd083 100644--- a/js/packages/react-ui/src/hooks/useScrollToBottom.ts+++ b/js/packages/react-ui/src/hooks/useScrollToBottom.ts@@ -1,4 +1,4 @@-import { RefObject, useEffect, useRef } from "react";+import { RefObject, useCallback, useEffect, useRef } from "react";export const useScrollToBottom = <T extends HTMLElement | null, L extends { id: string }>({ref,@@ -17,7 +17,7 @@ export const useScrollToBottom = <T extends HTMLElement | null, L extends { id:const previousLastMessage = useRef<L | null>(null);const lastUserMessage = useRef<HTMLElement | null>(null);- useEffect(() => {+ const scrollToBottom = useCallback(() => {const element = ref.current;if (!element) {return;@@ -63,11 +63,12 @@ export const useScrollToBottom = <T extends HTMLElement | null, L extends { id:}, [ref, lastMessage, scrollVariant, userMessageSelector]);useEffect(() => {+ scrollToBottom();+ }, [scrollToBottom]);++ useCallback(() => {if (isRunning) {- ref.current?.scrollTo({- top: ref.current?.scrollHeight,- behavior: "smooth",- });+ scrollToBottom();}}, [isRunning]);};