From f93b0dde79118bdc2fb13e85e129c4c84568311b Mon Sep 17 00:00:00 2001 From: Rocio Perez-Cano Date: Wed, 8 Nov 2023 14:34:57 -0500 Subject: [PATCH] Merge pull request #31072 from allroundexperts/fix-31027 fix: add null check to emoji suggestions (cherry picked from commit 05586ea7a8b015307a79cc20a5ebf851aa0f84ed) --- .../report/ReportActionCompose/Suggestions.js | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/pages/home/report/ReportActionCompose/Suggestions.js b/src/pages/home/report/ReportActionCompose/Suggestions.js index 0050b56800cc..05f35713c5f8 100644 --- a/src/pages/home/report/ReportActionCompose/Suggestions.js +++ b/src/pages/home/report/ReportActionCompose/Suggestions.js @@ -46,7 +46,23 @@ function Suggestions({ const suggestionEmojiRef = useRef(null); const suggestionMentionRef = useRef(null); - const getSuggestions = useCallback(() => suggestionEmojiRef.current.getSuggestions() || suggestionMentionRef.current.getSuggestions(), []); + const getSuggestions = useCallback(() => { + if (suggestionEmojiRef.current && suggestionEmojiRef.current.getSuggestions) { + const emojiSuggestions = suggestionEmojiRef.current.getSuggestions(); + if (emojiSuggestions.length > 0) { + return emojiSuggestions; + } + } + + if (suggestionMentionRef.current && suggestionMentionRef.current.getSuggestions) { + const mentionSuggestions = suggestionMentionRef.current.getSuggestions(); + if (mentionSuggestions.length > 0) { + return mentionSuggestions; + } + } + + return []; + }, []); /** * Clean data related to EmojiSuggestions