CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
sagemathinc

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/frontend/app-framework/use-bottom-scroller.ts
Views: 687
1
import { useRef } from "react";
2
3
import useDebounceEffect from "./use-debounce-effect";
4
5
export function useBottomScroller<T extends HTMLElement>(
6
scroll = false,
7
content: any,
8
) {
9
const paragraphRef = useRef<T>(null);
10
11
useDebounceEffect(
12
{
13
func: () => {
14
if (!scroll) return;
15
const p = paragraphRef.current;
16
if (p == null) return;
17
p.scrollTop = p.scrollHeight;
18
},
19
wait: 500,
20
options: { leading: true, trailing: true },
21
},
22
[content],
23
);
24
25
return paragraphRef;
26
}
27
28