From 4252a760f072da907d1b542e3bb9917db3f22b07 Mon Sep 17 00:00:00 2001 From: fragosti Date: Wed, 2 Jan 2019 16:55:29 +0100 Subject: feat: dont re-render the token selector on every input change --- .../src/components/erc20_token_selector.tsx | 39 +++++++++++++++++----- 1 file changed, 31 insertions(+), 8 deletions(-) (limited to 'packages/instant') diff --git a/packages/instant/src/components/erc20_token_selector.tsx b/packages/instant/src/components/erc20_token_selector.tsx index fc7c21d47..b5f01e349 100644 --- a/packages/instant/src/components/erc20_token_selector.tsx +++ b/packages/instant/src/components/erc20_token_selector.tsx @@ -26,7 +26,7 @@ export class ERC20TokenSelector extends React.PureComponent @@ -42,12 +42,11 @@ export class ERC20TokenSelector extends React.PureComponent - {_.map(tokens, token => { - if (!this._isTokenQueryMatch(token)) { - return null; - } - return ; - })} + ); @@ -59,8 +58,32 @@ export class ERC20TokenSelector extends React.PureComponent { + this.props.onTokenSelect(token); + }; +} + +interface TokenRowFilterProps { + tokens: ERC20Asset[]; + onClick: (token: ERC20Asset) => void; + searchQuery: string; +} + +class TokenRowFilter extends React.Component { + public render(): React.ReactNode { + return _.map(this.props.tokens, token => { + if (!this._isTokenQueryMatch(token)) { + return null; + } + return ; + }); + } + public shouldComponentUpdate(nextProps: TokenRowFilterProps): boolean { + const arePropsDeeplyEqual = _.isEqual(nextProps, this.props); + return !arePropsDeeplyEqual; + } private readonly _isTokenQueryMatch = (token: ERC20Asset): boolean => { - const { searchQuery } = this.state; + const { searchQuery } = this.props; const searchQueryLowerCase = searchQuery.toLowerCase().trim(); if (searchQueryLowerCase === '') { return true; -- cgit v1.2.3