Skip to content

Commit 7c502c3

Browse files
createthisamirfefer
authored andcommitted
fix: use getderivedstatefromprops
1 parent c1fd941 commit 7c502c3

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/index.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class EllipisWithTooltip extends React.Component {
1717
this.state = {
1818
hasOverflowingChildren: false,
1919
text: undefined,
20+
prevPropsChildren: props.children,
2021
};
2122
this.updateOverflow = this.updateOverflow.bind(this);
2223
}
@@ -35,9 +36,12 @@ class EllipisWithTooltip extends React.Component {
3536
}
3637
}
3738

38-
componentWillReceiveProps(nextProps) {
39-
if (nextProps.children === this.props.children) return;
40-
this.setState({ hasOverflowingChildren: false });
39+
static getDerivedStateFromProps(props, state) {
40+
if (props.children === state.prevPropsChildren) return null;
41+
return {
42+
hasOverflowingChildren: false,
43+
prevPropsChildren: props.children,
44+
};
4145
}
4246

4347
render() {

0 commit comments

Comments
 (0)