forked from p34709852/monkey
UI: Get derived state from props in AdvancedMultiSelect
This commit is contained in:
parent
18ceb6c279
commit
320364a7a2
|
@ -32,7 +32,6 @@ function AdvancedMultiSelectHeader(props) {
|
||||||
class AdvancedMultiSelect extends React.Component {
|
class AdvancedMultiSelect extends React.Component {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
|
|
||||||
let selectedPluginNames = this.props.value.map(v => v.name);
|
let selectedPluginNames = this.props.value.map(v => v.name);
|
||||||
let allPluginNames = this.props.options.enumOptions.map(v => v.value);
|
let allPluginNames = this.props.options.enumOptions.map(v => v.value);
|
||||||
|
|
||||||
|
@ -162,6 +161,16 @@ class AdvancedMultiSelect extends React.Component {
|
||||||
this.onChange(safePluginNames);
|
this.onChange(safePluginNames);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static getDerivedStateFromProps(props, current_state) {
|
||||||
|
let propsPluginNames = props.value.map(v => v.name);
|
||||||
|
if (current_state.selectedPluginNames !== propsPluginNames) {
|
||||||
|
return {
|
||||||
|
selectedPluginNames: propsPluginNames
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const {
|
const {
|
||||||
autofocus,
|
autofocus,
|
||||||
|
|
Loading…
Reference in New Issue