Repository navigation
Revert "Refactored toggleEmojiReaction to pure function" #73996
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| import React, {useCallback} from 'react'; | ||
| import React from 'react'; | ||
| import {View} from 'react-native'; | ||
| import type {Emoji} from '@assets/emojis/types'; | ||
| import AddReactionBubble from '@components/Reactions/AddReactionBubble'; | ||
|
|
@@ -28,13 +28,6 @@ function BaseQuickEmojiReactions({ | |
| const [preferredSkinTone = CONST.EMOJI_DEFAULT_SKIN_TONE] = useOnyx(ONYXKEYS.PREFERRED_EMOJI_SKIN_TONE, {canBeMissing: true}); | ||
| const [emojiReactions = getEmptyObject<ReportActionReactions>()] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS_REACTIONS}${reportActionID}`, {canBeMissing: true}); | ||
|
|
||
| const onEmojiSelectedWithReactions = useCallback( | ||
| (emoji: Emoji, skinTone: number) => { | ||
| onEmojiSelected(emoji, emojiReactions, skinTone); | ||
| }, | ||
| [onEmojiSelected, emojiReactions], | ||
| ); | ||
|
|
||
| return ( | ||
| <View style={styles.quickReactionsContainer}> | ||
| {CONST.QUICK_REACTIONS.map((emoji: Emoji) => ( | ||
|
|
@@ -46,7 +39,7 @@ function BaseQuickEmojiReactions({ | |
| <EmojiReactionBubble | ||
| emojiCodes={[getPreferredEmojiCode(emoji, preferredSkinTone)]} | ||
| isContextMenu | ||
| onPress={callFunctionIfActionIsAllowed(() => onEmojiSelected(emoji, emojiReactions, preferredSkinTone))} | ||
| onPress={callFunctionIfActionIsAllowed(() => onEmojiSelected(emoji, emojiReactions))} | ||
| /> | ||
| </View> | ||
| </Tooltip> | ||
|
|
@@ -55,7 +48,7 @@ function BaseQuickEmojiReactions({ | |
| isContextMenu | ||
| onPressOpenPicker={onPressOpenPicker} | ||
| onWillShowPicker={onWillShowPicker} | ||
| onSelectEmoji={onEmojiSelectedWithReactions} | ||
| onSelectEmoji={(emoji) => onEmojiSelected(emoji, emojiReactions)} | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❌ PERF-4 (docs)This inline arrow function creates a new function instance on every render because Suggested fix: Memoize the callback with const handleSelectEmoji = useCallback(
(emoji: Emoji) => {
onEmojiSelected(emoji, emojiReactions);
},
[onEmojiSelected, emojiReactions]
);
// Then use it in the JSX:
<AddReactionBubble
...
onSelectEmoji={handleSelectEmoji}
...
/> |
||
| reportAction={reportAction} | ||
| setIsEmojiPickerActive={setIsEmojiPickerActive} | ||
| /> | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❌ PERF-4 (docs)
This inline arrow function creates a new function instance on every render because it closes over
emojiReactions, which changes reference frequently. TheopenEmojiPickerfunction itself will be recreated on every render, causing unnecessary re-renders when passed as a callback.Suggested fix: Memoize the callback with
useCallback: