fix: Use getDerivedStateFromProps instead of componentWillReceiveProps (#372)

* use getDerivedStateFromProps instead of componentWillReceiveProps

* code formatting
release
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) this.handleKeyDown = this.handleKeyDown.bind(this)
} }
componentWillReceiveProps(props) { static getDerivedStateFromProps(props, state) {
if (props.skin) { if (props.skin) {
this.setState({ skin: props.skin }) return {
} else if (props.defaultSkin && !store.get('skin')) { ...state,
this.setState({ skin: props.defaultSkin }) skin: props.skin,
} }
} else if (props.defaultSkin && !store.get('skin')) {
return {
...state,
skin: props.defaultSkin,
}
}
return state
} }
componentDidMount() { componentDidMount() {