diff --git a/lib/hooks/inline-sidebar-text.react.js b/lib/hooks/inline-sidebar-text.react.js --- a/lib/hooks/inline-sidebar-text.react.js +++ b/lib/hooks/inline-sidebar-text.react.js @@ -9,18 +9,13 @@ import { pluralizeAndTrim } from '../utils/text-utils'; function useInlineSidebarText( - threadInfo: ThreadInfo, + threadInfo: ?ThreadInfo, ): { sendersText: string, repliesText: string, } { - const repliesCount = threadInfo.repliesCount || 1; - const repliesText = `${repliesCount} ${ - repliesCount > 1 ? 'replies' : 'reply' - }`; - const threadMembers = useSelector( - relativeMemberInfoSelectorForMembersOfThread(threadInfo.id), + relativeMemberInfoSelectorForMembersOfThread(threadInfo?.id), ); const sendersText = React.useMemo(() => { const senders = threadMembers @@ -29,13 +24,22 @@ return senders.length > 0 ? `${pluralizeAndTrim(senders, 25)} sent ` : ''; }, [threadMembers]); - return React.useMemo( - () => ({ + const noThreadInfo = !threadInfo; + + return React.useMemo(() => { + if (noThreadInfo) { + return { sendersText: '', repliesText: '' }; + } + const repliesCount = threadInfo?.repliesCount || 1; + const repliesText = `${repliesCount} ${ + repliesCount > 1 ? 'replies' : 'reply' + }`; + + return { sendersText, repliesText, - }), - [sendersText, repliesText], - ); + }; + }, [noThreadInfo, sendersText, threadInfo?.repliesCount]); } export default useInlineSidebarText;