Skip to content

Optimize large list performance #250

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

Merged
merged 2 commits into from
Feb 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/js/CheckboxTree.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import classNames from 'classnames';
import isEqual from 'lodash/isEqual';
import memoize from 'lodash/memoize';
import { nanoid } from 'nanoid';
import PropTypes from 'prop-types';
import React from 'react';
Expand Down Expand Up @@ -102,6 +103,8 @@ class CheckboxTree extends React.Component {
this.onNodeClick = this.onNodeClick.bind(this);
this.onExpandAll = this.onExpandAll.bind(this);
this.onCollapseAll = this.onCollapseAll.bind(this);

this.combineMemorized = memoize((icons1, icons2) => ({ ...icons1, ...icons2 })).bind(this);
}

// eslint-disable-next-line react/sort-comp
Expand Down Expand Up @@ -250,7 +253,7 @@ class CheckboxTree extends React.Component {
expandOnClick={expandOnClick}
expanded={flatNode.expanded}
icon={node.icon}
icons={{ ...defaultIcons, ...icons }}
icons={this.combineMemorized(defaultIcons, icons)}
label={node.label}
lang={lang}
optimisticToggle={optimisticToggle}
Expand Down
2 changes: 1 addition & 1 deletion src/js/TreeNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import NativeCheckbox from './NativeCheckbox';
import iconsShape from './shapes/iconsShape';
import languageShape from './shapes/languageShape';

class TreeNode extends React.Component {
class TreeNode extends React.PureComponent {
static propTypes = {
checked: PropTypes.number.isRequired,
disabled: PropTypes.bool.isRequired,
Expand Down