Skip to content

Commit

Permalink
Attempt 2: Try using shouldcomponentupdate-children in the
Browse files Browse the repository at this point in the history
template function creator.

See this medium article:

https://medium.com/myheritage-engineering/how-to-greatly-improve-your-react-app-performance-e70f7cbbb5f6

Unfortunately, this implementation only causes the react-table to not
update at all.

From the author of the library:
> Instead of checking the comparison this.props.children !==
> nextProps.children, we will depend on a different prop to
> indicate a state change, preferably a string/numeric one,
> in order to make the comparison a very fast one.

This seems very difficult to implement in react-table.
  • Loading branch information
Matthew Reishus authored and Matthew Reishus committed Jan 22, 2018
1 parent dc5b374 commit e496506
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"react": "^16.2.0",
"react-dom": "^16.2.0",
"react-scripts": "1.1.0",
"react-table": "^6.7.6"
"react-table": "^6.7.6",
"shouldcomponentupdate-children": "^1.1.0"
},
"scripts": {
"start": "react-scripts start",
Expand Down
23 changes: 18 additions & 5 deletions src/external/react-table-modified/src/utils.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import React from "react";
import classnames from "classnames";
import { shallowEqual } from "shouldcomponentupdate-children";

//
export default {
get,
Expand Down Expand Up @@ -126,11 +128,22 @@ function makeTemplateComponent(compClass, displayName) {
if (!displayName) {
throw new Error("No displayName found for template component:", compClass);
}
const cmp = ({ children, className, ...rest }) => (
<div className={classnames(compClass, className)} {...rest}>
{children}
</div>
);

let cmp = class extends React.Component {
shouldComponentUpdate(nextProps, nextState) {
return shallowEqual(this.props, nextProps, this.state, nextState);
}

render() {
const { children, className, ...rest } = this.props;
return (
<div className={classnames(compClass, className)} {...rest}>
{children}
</div>
);
}
};

cmp.displayName = displayName;
return cmp;
}
Expand Down
4 changes: 4 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5698,6 +5698,10 @@ shellwords@^0.1.1:
version "0.1.1"
resolved "https://registry.yarnpkg.com/shellwords/-/shellwords-0.1.1.tgz#d6b9181c1a48d397324c84871efbcfc73fc0654b"

shouldcomponentupdate-children@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/shouldcomponentupdate-children/-/shouldcomponentupdate-children-1.1.0.tgz#cbabccc9af8bc8f6d345f0506769ff2b5fe95147"

signal-exit@^3.0.0, signal-exit@^3.0.2:
version "3.0.2"
resolved "https://registry.yarnpkg.com/signal-exit/-/signal-exit-3.0.2.tgz#b5fdc08f1287ea1178628e415e25132b73646c6d"
Expand Down

0 comments on commit e496506

Please sign in to comment.