Skip to content

Commit

Permalink
use getDerivedStateFromProps instead of componentWillReceiveProps
Browse files Browse the repository at this point in the history
  • Loading branch information
hosseinmd committed Dec 11, 2019
1 parent dad86d4 commit e1b85b5
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions source/line.js
Expand Up @@ -13,10 +13,13 @@ export default class Line extends PureComponent {
this.setState(props);
}

componentWillReceiveProps(nextProps) {
if (nextProps.color !== this.props.color) {
this.setState({ color: nextProps.color });
static getDerivedStateFromProps(props, state) {
if (props.color !== state.color) {
return {
color: props.color,
};
}
return null;
}

render() {
Expand Down

0 comments on commit e1b85b5

Please sign in to comment.