UI: Get derived state from props in AdvancedMultiSelect

This commit is contained in:
Ilija Lazoroski 2022-09-21 16:48:47 +02:00
parent 18ceb6c279
commit 320364a7a2
1 changed files with 10 additions and 1 deletions

View File

@ -32,7 +32,6 @@ function AdvancedMultiSelectHeader(props) {
class AdvancedMultiSelect extends React.Component {
constructor(props) {
super(props);
let selectedPluginNames = this.props.value.map(v => v.name);
let allPluginNames = this.props.options.enumOptions.map(v => v.value);
@ -162,6 +161,16 @@ class AdvancedMultiSelect extends React.Component {
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() {
const {
autofocus,