@assistant-ui/react
Version:
Open-source TypeScript/React library for building production-grade AI chat experiences
20 lines (16 loc) • 753 B
text/typescript
"use client";
import { useIsomorphicLayoutEffect } from "../../../utils/useIsomorphicLayoutEffect";
import { useThreadViewportStore } from "../../../context/react/ThreadViewportContext";
import { mountTopAnchorReserve } from "./mountTopAnchorReserve";
/**
* Mounts the top-turn-anchor reserve element against the active
* `ThreadViewport` store. Call this from inside the scrollable viewport so
* the reserve `<div>` is appended next to the streaming assistant message.
*/
export const useTopAnchorReserve = (enabled: boolean) => {
const threadViewportStore = useThreadViewportStore();
useIsomorphicLayoutEffect(() => {
if (!enabled) return;
return mountTopAnchorReserve(threadViewportStore);
}, [enabled, threadViewportStore]);
};