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