Get rid of custom components folder
This commit is contained in:
parent
c493ac342b
commit
6d16f67280
38 changed files with 34 additions and 34 deletions
31
components/use-scroll-to-bottom.ts
Normal file
31
components/use-scroll-to-bottom.ts
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
import { useEffect, useRef, RefObject } from 'react';
|
||||
|
||||
export function useScrollToBottom<T extends HTMLElement>(): [
|
||||
RefObject<T>,
|
||||
RefObject<T>,
|
||||
] {
|
||||
const containerRef = useRef<T>(null);
|
||||
const endRef = useRef<T>(null);
|
||||
|
||||
useEffect(() => {
|
||||
const container = containerRef.current;
|
||||
const end = endRef.current;
|
||||
|
||||
if (container && end) {
|
||||
const observer = new MutationObserver(() => {
|
||||
end.scrollIntoView({ behavior: 'instant', block: 'end' });
|
||||
});
|
||||
|
||||
observer.observe(container, {
|
||||
childList: true,
|
||||
subtree: true,
|
||||
attributes: true,
|
||||
characterData: true,
|
||||
});
|
||||
|
||||
return () => observer.disconnect();
|
||||
}
|
||||
}, []);
|
||||
|
||||
return [containerRef, endRef];
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue