Cache onHeightChange property of message

This commit is contained in:
Fedor Indutny 2021-08-06 14:43:18 -07:00 committed by GitHub
parent 78447a0018
commit 46b1e8d0e7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -4,6 +4,8 @@
import { isEmpty, mapValues, pick } from 'lodash'; import { isEmpty, mapValues, pick } from 'lodash';
import React from 'react'; import React from 'react';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import memoizee from 'memoizee';
import { mapDispatchToProps } from '../actions'; import { mapDispatchToProps } from '../actions';
import { import {
ContactSpoofingReviewPropType, ContactSpoofingReviewPropType,
@ -56,6 +58,16 @@ type ExternalProps = {
// are provided by ConversationView in setupTimeline(). // are provided by ConversationView in setupTimeline().
}; };
const createBoundOnHeightChange = memoizee(
(
onHeightChange: (messageId: string) => unknown,
messageId: string
): (() => unknown) => {
return () => onHeightChange(messageId);
},
{ max: 500 }
);
function renderItem( function renderItem(
messageId: string, messageId: string,
conversationId: string, conversationId: string,
@ -67,7 +79,7 @@ function renderItem(
{...actionProps} {...actionProps}
conversationId={conversationId} conversationId={conversationId}
id={messageId} id={messageId}
onHeightChange={() => onHeightChange(messageId)} onHeightChange={createBoundOnHeightChange(onHeightChange, messageId)}
renderEmojiPicker={renderEmojiPicker} renderEmojiPicker={renderEmojiPicker}
renderAudioAttachment={renderAudioAttachment} renderAudioAttachment={renderAudioAttachment}
/> />