@@ -349,8 +349,8 @@ const MessageListWithContext = <
349349 const [ lastReceivedId , setLastReceivedId ] = useState ( getLastReceivedMessage ( messageList ) ?. id ) ;
350350 const [ scrollToBottomButtonVisible , setScrollToBottomButtonVisible ] = useState ( false ) ;
351351
352- const [ stickyHeaderDate , setStickyHeaderDate ] = useState < Date > ( new Date ( ) ) ;
353- const stickyHeaderDateRef = useRef ( new Date ( ) ) ;
352+ const [ stickyHeaderDate , setStickyHeaderDate ] = useState < Date | undefined > ( ) ;
353+ const stickyHeaderDateRef = useRef < Date | undefined > ( ) ;
354354 /**
355355 * channel.lastRead throws error if the channel is not initialized.
356356 */
@@ -396,7 +396,7 @@ const MessageListWithContext = <
396396 lastItem ?. item ?. created_at &&
397397 ! lastItem . item . deleted_at &&
398398 typeof lastItem . item . created_at !== 'string' &&
399- lastItem . item . created_at . toDateString ( ) !== stickyHeaderDateRef . current . toDateString ( )
399+ lastItem . item . created_at . toDateString ( ) !== stickyHeaderDateRef . current ? .toDateString ( )
400400 ) {
401401 stickyHeaderDateRef . current = lastItem . item . created_at ;
402402 setStickyHeaderDate ( lastItem . item . created_at ) ;
@@ -819,11 +819,14 @@ const MessageListWithContext = <
819819 } , [ imageString , numberOfMessagesWithImages , threadExists , threadList ] ) ;
820820
821821 const stickyHeaderFormatDate =
822- stickyHeaderDate . getFullYear ( ) === new Date ( ) . getFullYear ( ) ? 'MMM D' : 'MMM D, YYYY' ;
823- const tStickyHeaderDate = tDateTimeParser ( stickyHeaderDate ) ;
824- const stickyHeaderDateToRender = isDayOrMoment ( tStickyHeaderDate )
825- ? tStickyHeaderDate . format ( stickyHeaderFormatDate )
826- : new Date ( tStickyHeaderDate ) . toDateString ( ) ;
822+ stickyHeaderDate ?. getFullYear ( ) === new Date ( ) . getFullYear ( ) ? 'MMM D' : 'MMM D, YYYY' ;
823+ const tStickyHeaderDate = stickyHeaderDate ? tDateTimeParser ( stickyHeaderDate ) : null ;
824+ const stickyHeaderDateToRender =
825+ tStickyHeaderDate === null
826+ ? null
827+ : isDayOrMoment ( tStickyHeaderDate )
828+ ? tStickyHeaderDate . format ( stickyHeaderFormatDate )
829+ : new Date ( tStickyHeaderDate ) . toDateString ( ) ;
827830
828831 const dismissImagePicker = ( ) => {
829832 if ( ! hasMoved && selectedPicker ) {
@@ -890,11 +893,12 @@ const MessageListWithContext = <
890893 { ! loading && (
891894 < >
892895 < View style = { styles . stickyHeader } >
893- { StickyHeader ? (
894- < StickyHeader dateString = { stickyHeaderDateToRender } />
895- ) : messageListLengthAfterUpdate ? (
896- < DateHeader dateString = { stickyHeaderDateToRender } />
897- ) : null }
896+ { stickyHeaderDateToRender &&
897+ ( StickyHeader ? (
898+ < StickyHeader dateString = { stickyHeaderDateToRender } />
899+ ) : messageListLengthAfterUpdate ? (
900+ < DateHeader dateString = { stickyHeaderDateToRender } />
901+ ) : null ) }
898902 </ View >
899903 { ! disableTypingIndicator && TypingIndicator && typingEventsEnabled !== false && (
900904 < TypingIndicatorContainer >
0 commit comments