Skip to content

Commit

Permalink
Merge pull request #2 from DaherHexa/main
Browse files Browse the repository at this point in the history
Make sure ref.current not null before accessing fields
  • Loading branch information
jclarkk authored Sep 11, 2023
2 parents bce9bb1 + a85f4a0 commit fec4421
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/components/hooks/use-chat-scroll-anchor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ export const useChatScrollAnchor = (

useEffect(() => {
const handleScroll = () => {
const { scrollTop, clientHeight, scrollHeight } = ref.current;
const atBottom = (scrollHeight - scrollTop) === clientHeight;
setAutoScroll(atBottom);
if (ref.current) {
const {scrollTop, clientHeight, scrollHeight} = ref.current;
const atBottom = (scrollHeight - scrollTop) === clientHeight;
setAutoScroll(atBottom);
}
}

if (ref.current) {
Expand Down

0 comments on commit fec4421

Please sign in to comment.