mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-01-09 12:08:50 +01:00
refactor: Enhance ScrollToBottom component with forwardRef for improved functionality
- Updated ScrollToBottom component to use forwardRef, allowing it to accept a ref for better integration with parent components. - Modified MessagesView to utilize the new ref for the ScrollToBottom button, improving scrolling behavior and performance.
This commit is contained in:
parent
c96f8997fe
commit
20db2394d2
2 changed files with 12 additions and 5 deletions
|
|
@ -1,4 +1,4 @@
|
|||
import { useState } from 'react';
|
||||
import { useState, useRef } from 'react';
|
||||
import { useAtomValue } from 'jotai';
|
||||
import { useRecoilValue } from 'recoil';
|
||||
import { CSSTransition } from 'react-transition-group';
|
||||
|
|
@ -21,6 +21,7 @@ function MessagesViewContent({
|
|||
const { screenshotTargetRef } = useScreenshot();
|
||||
const scrollButtonPreference = useRecoilValue(store.showScrollButton);
|
||||
const [currentEditId, setCurrentEditId] = useState<number | string | null>(-1);
|
||||
const scrollToBottomRef = useRef<HTMLButtonElement>(null);
|
||||
|
||||
const {
|
||||
conversation,
|
||||
|
|
@ -87,8 +88,9 @@ function MessagesViewContent({
|
|||
classNames="scroll-animation"
|
||||
unmountOnExit={true}
|
||||
appear={true}
|
||||
nodeRef={scrollToBottomRef}
|
||||
>
|
||||
<ScrollToBottom scrollHandler={handleSmoothToRef} />
|
||||
<ScrollToBottom ref={scrollToBottomRef} scrollHandler={handleSmoothToRef} />
|
||||
</CSSTransition>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -1,12 +1,13 @@
|
|||
import React from 'react';
|
||||
import { forwardRef } from 'react';
|
||||
|
||||
type Props = {
|
||||
scrollHandler: React.MouseEventHandler<HTMLButtonElement>;
|
||||
};
|
||||
|
||||
export default function ScrollToBottom({ scrollHandler }: Props) {
|
||||
const ScrollToBottom = forwardRef<HTMLButtonElement, Props>(({ scrollHandler }, ref) => {
|
||||
return (
|
||||
<button
|
||||
ref={ref}
|
||||
onClick={scrollHandler}
|
||||
className="premium-scroll-button absolute bottom-5 right-1/2 cursor-pointer border border-border-light bg-surface-secondary"
|
||||
aria-label="Scroll to bottom"
|
||||
|
|
@ -22,4 +23,8 @@ export default function ScrollToBottom({ scrollHandler }: Props) {
|
|||
</svg>
|
||||
</button>
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
ScrollToBottom.displayName = 'ScrollToBottom';
|
||||
|
||||
export default ScrollToBottom;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue