File tree Expand file tree Collapse file tree 2 files changed +13
-8
lines changed
hooks/useHandleOnScrollCallback
modules/Channel/components/MessageList Expand file tree Collapse file tree 2 files changed +13
-8
lines changed Original file line number Diff line number Diff line change @@ -19,7 +19,11 @@ export function useHandleOnScrollCallback({
1919 setShowScrollDownButton,
2020} : UseHandleOnScrollCallbackProps ) : ( ) => void {
2121 return useCallback ( ( ) => {
22- const element = scrollRef . current ;
22+ const element = scrollRef ?. current ;
23+ if ( element == null ) {
24+ return ;
25+ }
26+
2327 const {
2428 scrollTop,
2529 scrollHeight,
@@ -40,7 +44,7 @@ export function useHandleOnScrollCallback({
4044 if ( scrollTop < SCROLL_BUFFER ) {
4145 onScroll ( ( ) => {
4246 // sets the scroll position to the bottom of the new messages
43- scrollRef . current . scrollTop = scrollRef . current . scrollHeight - scrollBottom ;
47+ element . scrollTop = element . scrollHeight - scrollBottom ;
4448 } ) ;
4549 }
4650 } , [
Original file line number Diff line number Diff line change @@ -58,8 +58,12 @@ const MessageList: React.FC<MessageListProps> = ({
5858 : allMessages ;
5959 const markAsReadScheduler = store . config . markAsReadScheduler ;
6060
61- const onScroll = ( e ) => {
62- const element = e . target ;
61+ const onScroll = ( ) => {
62+ const element = scrollRef ?. current ;
63+ if ( element == null ) {
64+ return ;
65+ }
66+
6367 const {
6468 scrollTop,
6569 clientHeight,
@@ -80,10 +84,7 @@ const MessageList: React.FC<MessageListProps> = ({
8084 }
8185
8286 // Save the lastest scroll bottom value
83- if ( scrollRef ?. current ) {
84- const current = scrollRef ?. current ;
85- setScrollBottom ( current . scrollHeight - current . scrollTop - current . offsetHeight )
86- }
87+ setScrollBottom ( element . scrollHeight - element . scrollTop - element . offsetHeight )
8788
8889 if ( ! disableMarkAsRead && isAboutSame ( clientHeight + scrollTop , scrollHeight , SCROLL_BUFFER ) ) {
8990 messagesDispatcher ( {
You can’t perform that action at this time.
0 commit comments