CoinList: memoize coinList for performance

This commit is contained in:
Alex Gleason 2021-07-01 19:37:49 -05:00
parent e7d360baae
commit 8961fc1b68
No known key found for this signature in database
GPG Key ID: 7211D1F99744FBB7
1 changed files with 24 additions and 10 deletions

View File

@ -4,6 +4,17 @@ import PropTypes from 'prop-types';
import ImmutablePropTypes from 'react-immutable-proptypes';
import ImmutablePureComponent from 'react-immutable-pure-component';
import CryptoAddress from './crypto_address';
import { createSelector } from 'reselect';
const makeGetCoinList = () => {
return createSelector(
[(addresses, limit) => typeof limit === 'number' ? addresses.take(limit) : addresses],
addresses => addresses,
);
};
const makeMapStateToProps = () => {
const getCoinList = makeGetCoinList();
const mapStateToProps = (state, ownProps) => {
// Address example:
@ -12,11 +23,14 @@ const mapStateToProps = (state, ownProps) => {
const { limit } = ownProps;
return {
coinList: typeof limit === 'number' ? addresses.take(limit) : addresses,
coinList: getCoinList(addresses, limit),
};
};
export default @connect(mapStateToProps)
return mapStateToProps;
};
export default @connect(makeMapStateToProps)
class CoinList extends ImmutablePureComponent {
static propTypes = {