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,18 @@ import { pluralizeAndTrim } from '../utils/text-utils'; function useInlineSidebarText( - threadInfo: ThreadInfo, + threadInfo: ?ThreadInfo, ): { sendersText: string, repliesText: string, } { - const repliesCount = threadInfo.repliesCount || 1; + 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 +29,15 @@ return senders.length > 0 ? `${pluralizeAndTrim(senders, 25)} sent ` : ''; }, [threadMembers]); - return React.useMemo( - () => ({ + return React.useMemo(() => { + if (!threadInfo) { + return { sendersText: '', repliesText: '' }; + } + return { sendersText, repliesText, - }), - [sendersText, repliesText], - ); + }; + }, [threadInfo, sendersText, repliesText]); } export default useInlineSidebarText;