fix: Use getDerivedStateFromProps instead of componentWillReceiveProps (#372)

* use getDerivedStateFromProps instead of componentWillReceiveProps

* code formatting
nolan/no-underscore-json
Hiro-Aki Hotta 2019-12-22 01:43:36 +09:00 committed by Nolan Lawson
parent f10510b262
commit 208099c2dc
1 changed files with 10 additions and 3 deletions

View File

@ -176,12 +176,19 @@ export default class NimblePicker extends React.PureComponent {
this.handleKeyDown = this.handleKeyDown.bind(this)
}
componentWillReceiveProps(props) {
static getDerivedStateFromProps(props, state) {
if (props.skin) {
this.setState({ skin: props.skin })
return {
...state,
skin: props.skin,
}
} else if (props.defaultSkin && !store.get('skin')) {
this.setState({ skin: props.defaultSkin })
return {
...state,
skin: props.defaultSkin,
}
}
return state
}
componentDidMount() {