Skip to content

Commit 546c8bb

Browse files
author
Tom Hutman
committed
pull out SuggestionListContainer component from render method, put in separate class method to prevent re-renders of the same component
1 parent 95ab0b4 commit 546c8bb

File tree

1 file changed

+41
-42
lines changed

1 file changed

+41
-42
lines changed

src/components/AutoCompleteTextarea/Textarea.js

Lines changed: 41 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -619,62 +619,61 @@ class ReactTextareaAutocomplete extends React.Component {
619619
scrollToItem(this.dropdownRef, item);
620620
};
621621

622-
render() {
622+
renderSuggestionListContainer() {
623623
const {
624-
className,
625-
containerClassName,
626-
containerStyle,
627624
disableMentions,
628625
dropdownClassName,
629626
dropdownStyle,
630627
itemClassName,
631628
itemStyle,
632629
listClassName,
633-
style,
634630
SuggestionList = DefaultSuggestionList,
635631
} = this.props;
636-
637-
let { maxRows } = this.props;
638-
639632
const { component, currentTrigger, dataLoading, value } = this.state;
640633

641634
const selectedItem = this._getItemOnSelect();
642635
const suggestionData = this._getSuggestions();
643636
const textToReplace = this._getTextToReplace();
644637

645-
const SuggestionListContainer = () => {
646-
if (
647-
(dataLoading || suggestionData) &&
648-
currentTrigger &&
649-
!(disableMentions && currentTrigger === '@')
650-
) {
651-
return (
652-
<div
653-
className={`rta__autocomplete ${dropdownClassName || ''}`}
654-
ref={(ref) => {
655-
this.dropdownRef = ref;
656-
}}
657-
style={dropdownStyle}
658-
>
659-
{component && suggestionData && textToReplace && (
660-
<SuggestionList
661-
className={listClassName}
662-
component={component}
663-
dropdownScroll={this._dropdownScroll}
664-
getSelectedItem={selectedItem}
665-
getTextToReplace={textToReplace}
666-
itemClassName={itemClassName}
667-
itemStyle={itemStyle}
668-
onSelect={this._onSelect}
669-
value={value}
670-
values={suggestionData}
671-
/>
672-
)}
673-
</div>
674-
);
675-
}
676-
return null;
677-
};
638+
if (
639+
(dataLoading || suggestionData) &&
640+
currentTrigger &&
641+
!(disableMentions && currentTrigger === '@')
642+
) {
643+
return (
644+
<div
645+
className={`rta__autocomplete ${dropdownClassName || ''}`}
646+
ref={(ref) => {
647+
this.dropdownRef = ref;
648+
}}
649+
style={dropdownStyle}
650+
>
651+
{component && suggestionData && textToReplace && (
652+
<SuggestionList
653+
className={listClassName}
654+
component={component}
655+
dropdownScroll={this._dropdownScroll}
656+
getSelectedItem={selectedItem}
657+
getTextToReplace={textToReplace}
658+
itemClassName={itemClassName}
659+
itemStyle={itemStyle}
660+
onSelect={this._onSelect}
661+
value={value}
662+
values={suggestionData}
663+
/>
664+
)}
665+
</div>
666+
);
667+
}
668+
return null;
669+
}
670+
671+
render() {
672+
const { className, containerClassName, containerStyle, style } = this.props;
673+
674+
let { maxRows } = this.props;
675+
676+
const { dataLoading, value } = this.state;
678677

679678
if (!this.props.grow) maxRows = 1;
680679

@@ -685,7 +684,7 @@ class ReactTextareaAutocomplete extends React.Component {
685684
}`}
686685
style={containerStyle}
687686
>
688-
<SuggestionListContainer />
687+
{this.renderSuggestionListContainer()}
689688
<Textarea
690689
{...this._cleanUpProps()}
691690
className={`rta__textarea ${className || ''}`}

0 commit comments

Comments
 (0)