diff --git a/lib/hooks/account-hooks.js b/lib/hooks/account-hooks.js new file mode 100644 --- /dev/null +++ b/lib/hooks/account-hooks.js @@ -0,0 +1,14 @@ +// @flow + +import type { LoggedInUserInfo } from '../types/user-types.js'; +import { useSelector } from '../utils/redux-utils.js'; + +function useLoggedInUserInfo(): ?LoggedInUserInfo { + return useSelector(state => + state.currentUserInfo && !state.currentUserInfo.anonymous + ? state.currentUserInfo + : null, + ); +} + +export { useLoggedInUserInfo }; diff --git a/web/chat/thread-list-provider.js b/web/chat/thread-list-provider.js --- a/web/chat/thread-list-provider.js +++ b/web/chat/thread-list-provider.js @@ -3,6 +3,7 @@ import invariant from 'invariant'; import * as React from 'react'; +import { useLoggedInUserInfo } from 'lib/hooks/account-hooks.js'; import { type ChatThreadItem, useFlattenedChatListData, @@ -169,9 +170,8 @@ const chatListData = useFlattenedChatListData(); const [searchText, setSearchText] = React.useState(''); - const viewerID = useSelector( - state => state.currentUserInfo && state.currentUserInfo.id, - ); + const loggedInUserInfo = useLoggedInUserInfo(); + const viewerID = loggedInUserInfo?.id; const { threadSearchResults, usersSearchResults } = useThreadListSearch( chatListData,