Skip to content

Commit

Permalink
fix(chat): update useIntersectionObserver usage
Browse files Browse the repository at this point in the history
  • Loading branch information
mortalYoung committed Jan 13, 2025
1 parent 8b5a597 commit 36e346a
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions src/chat/message/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ export default function Message({
onStop,
onLazyRendered,
}: IMessageProps) {
const divRef = useRef<HTMLDivElement>(null);
const divRef = useIntersectionObserver<HTMLDivElement>(handleObserverCb);
const { components = {}, messageIcons, rehypePlugins, remarkPlugins } = useContext();

// 当前 Message 的懒加载,是否已经加载过
const [lazyRendered, setLazyRendered] = useState(false);
const mountCallback = useRef(() => {});

const handleObserverCb = ([entry]: IntersectionObserverEntry[]) => {
function handleObserverCb([entry]: IntersectionObserverEntry[]) {
if (entry.isIntersecting) {
setLazyRendered((p) => {
if (!p) {
Expand All @@ -58,9 +58,7 @@ export default function Message({
return true;
});
}
};

useIntersectionObserver(handleObserverCb, divRef);
}

const [current, setCurrent] = useState(data.length);

Expand Down

0 comments on commit 36e346a

Please sign in to comment.