Skip to content
This repository has been archived by the owner on Sep 29, 2023. It is now read-only.

Adding deep-equal stops unnecessary re-renders #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
17 changes: 16 additions & 1 deletion src/components/Link/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -148,10 +156,17 @@ class LinkWithMiddleware extends React.PureComponent {
props => <Link {...(props: any)} />
);

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);