From 8b164711a4dde8b8d42cb7b1f800640b04c8b229 Mon Sep 17 00:00:00 2001 From: Harrison Healey Date: Fri, 14 Feb 2025 16:21:52 -0500 Subject: [PATCH] MM-63138 Fix some console warnings (#30209) * Fix forwardRef propTypes console error The console error that was fixed by this is: "Warning: forwardRef render functions do not support propTypes or defaultProps. Did you accidentally pass a React component?" * Fix function component ref console error This fixes the following error: Warning: Function components cannot be given refs. Attempts to access this ref will fail. Did you mean to use React. forwardRef ()? --- .../new_search/search_box_input.tsx | 6 ++--- .../__snapshots__/thread_footer.test.tsx.snap | 20 +++++++------- .../threading/common/button/button.tsx | 27 +++++++++++-------- .../__snapshots__/follow_button.test.tsx.snap | 8 +++--- 4 files changed, 33 insertions(+), 28 deletions(-) diff --git a/webapp/channels/src/components/new_search/search_box_input.tsx b/webapp/channels/src/components/new_search/search_box_input.tsx index 1b0faa6900..92347e5b93 100644 --- a/webapp/channels/src/components/new_search/search_box_input.tsx +++ b/webapp/channels/src/components/new_search/search_box_input.tsx @@ -75,7 +75,7 @@ type Props = { focus: (newPosition: number) => void; } -const SearchInput = ({searchTerms, searchType, setSearchTerms, onKeyDown, focus}: Props, inputRef: React.Ref) => { +const SearchInput = forwardRef(({searchTerms, searchType, setSearchTerms, onKeyDown, focus}, inputRef) => { const intl = useIntl(); let searchPlaceholder = intl.formatMessage({id: 'search_bar.search', defaultMessage: 'Search'}); @@ -131,6 +131,6 @@ const SearchInput = ({searchTerms, searchType, setSearchTerms, onKeyDown, focus} )} ); -}; +}); -export default forwardRef(SearchInput); +export default SearchInput; diff --git a/webapp/channels/src/components/threading/channel_threads/thread_footer/__snapshots__/thread_footer.test.tsx.snap b/webapp/channels/src/components/threading/channel_threads/thread_footer/__snapshots__/thread_footer.test.tsx.snap index f5a967e52f..a92d4fec15 100644 --- a/webapp/channels/src/components/threading/channel_threads/thread_footer/__snapshots__/thread_footer.test.tsx.snap +++ b/webapp/channels/src/components/threading/channel_threads/thread_footer/__snapshots__/thread_footer.test.tsx.snap @@ -15,7 +15,7 @@ exports[`components/threading/channel_threads/thread_footer should match snapsho isFollowing={true} onClick={[Function]} > - - + @@ -317,7 +317,7 @@ exports[`components/threading/channel_threads/thread_footer should report total - - + - - + - - + - - + , Props> -function Button({ - prepend, - append, - children, - isActive, - hasDot, - marginTop, - allowTextOverflow = false, - ...attrs -}: Props & Attrs) { +const Button = React.forwardRef(( + { + prepend, + append, + children, + isActive, + hasDot, + marginTop, + allowTextOverflow = false, + ...attrs + }, + ref, +) => { return ( ); -} +}); +Button.displayName = 'Button'; export default memo(Button); diff --git a/webapp/channels/src/components/threading/common/follow_button/__snapshots__/follow_button.test.tsx.snap b/webapp/channels/src/components/threading/common/follow_button/__snapshots__/follow_button.test.tsx.snap index 94aeeeb4a8..0b069e27e9 100644 --- a/webapp/channels/src/components/threading/common/follow_button/__snapshots__/follow_button.test.tsx.snap +++ b/webapp/channels/src/components/threading/common/follow_button/__snapshots__/follow_button.test.tsx.snap @@ -5,7 +5,7 @@ exports[`components/threading/common/follow_button should say follow 1`] = ` isFollowing={false} onClick={[MockFunction]} > - - + `; @@ -30,7 +30,7 @@ exports[`components/threading/common/follow_button should say following 1`] = ` - - + `;