From 3dfdfef4a13d54213454921e6040f89e0ff884b2 Mon Sep 17 00:00:00 2001 From: Jonathan King Date: Fri, 18 Aug 2017 17:42:53 +0100 Subject: [PATCH] Adding deep-equal stops unnecessary re-renders --- src/components/Link/index.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/components/Link/index.js b/src/components/Link/index.js index 7562287..100f57d 100644 --- a/src/components/Link/index.js +++ b/src/components/Link/index.js @@ -102,6 +102,14 @@ class Link extends React.PureComponent { return !!match; }; + shouldComponentUpdate(nextProps) { + const props = {...nextProps}; + if (!props.children || !props.children.length) { + delete props.children; + } + return !deepEqual(this.props, nextProps); + } + render() { const { history, @@ -148,10 +156,17 @@ class LinkWithMiddleware extends React.PureComponent { props => ); + shouldComponentUpdate(nextProps) { + const props = {...nextProps}; + if (!props.children || !props.children.length) { + delete props.children; + } + return !deepEqual(this.props, nextProps); + } + render() { return this.renderWithMiddleware(this.props); } } export default withRouter(LinkWithMiddleware); -