Skip to content

Commit 3530ae4

Browse files
authored
Merge pull request #131 from Yoctol/react-memo
add React.memo to avoid unnecessary re-render
2 parents 7544c16 + b03cd6d commit 3530ae4

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

package-lock.json

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"d3-scale-chromatic": "^2.0.0",
3333
"d3-selection": "^2.0.0",
3434
"prop-types": "^15.7.2",
35+
"react-fast-compare": "^3.2.0",
3536
"react-faux-dom": "^4.5.0"
3637
},
3738
"peerDependencies": {

src/WordCloud.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import PropTypes from 'prop-types';
2+
import React, { useRef } from 'react';
23
import ReactFauxDom from 'react-faux-dom';
34
import cloud from 'd3-cloud';
5+
import isDeepEqual from 'react-fast-compare';
46
import { scaleOrdinal } from 'd3-scale';
57
import { schemeCategory10 } from 'd3-scale-chromatic';
68
import { select } from 'd3-selection';
7-
import { useRef } from 'react';
89

910
// From: https://github.com/jasondavies/d3-cloud/blob/4fc1a943d01d270e7838c97bb8ee48ca15da20be/index.js#L355-L378
1011
function archimedeanSpiral(size) {
@@ -173,4 +174,4 @@ WordCloud.defaultProps = {
173174
onWordMouseOut: null,
174175
};
175176

176-
export default WordCloud;
177+
export default React.memo(WordCloud, isDeepEqual);

0 commit comments

Comments
 (0)