mirror of
				https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web.git
				synced 2025-11-04 16:23:41 +08:00 
			
		
		
		
	refactor: 优化 useScrollToBottom
This commit is contained in:
		@@ -3,8 +3,8 @@ import React, {
 | 
			
		||||
  useState,
 | 
			
		||||
  useRef,
 | 
			
		||||
  useEffect,
 | 
			
		||||
  useLayoutEffect,
 | 
			
		||||
  useMemo,
 | 
			
		||||
  useCallback,
 | 
			
		||||
} from "react";
 | 
			
		||||
 | 
			
		||||
import SendWhiteIcon from "../icons/send-white.svg";
 | 
			
		||||
@@ -341,15 +341,15 @@ function useScrollToBottom() {
 | 
			
		||||
  // for auto-scroll
 | 
			
		||||
  const scrollRef = useRef<HTMLDivElement>(null);
 | 
			
		||||
  const [autoScroll, setAutoScroll] = useState(true);
 | 
			
		||||
  const scrollToBottom = () => {
 | 
			
		||||
  const scrollToBottom = useCallback(() => {
 | 
			
		||||
    const dom = scrollRef.current;
 | 
			
		||||
    if (dom) {
 | 
			
		||||
      setTimeout(() => (dom.scrollTop = dom.scrollHeight), 1);
 | 
			
		||||
      requestAnimationFrame(() => dom.scrollTo(0, dom.scrollHeight));
 | 
			
		||||
    }
 | 
			
		||||
  };
 | 
			
		||||
  }, []);
 | 
			
		||||
 | 
			
		||||
  // auto scroll
 | 
			
		||||
  useLayoutEffect(() => {
 | 
			
		||||
  useEffect(() => {
 | 
			
		||||
    autoScroll && scrollToBottom();
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user