reactjs - React-Select -- Get unselected value -




i'm using react-select in current app , can't seem find way unselected value. i'm new react maybe there "react" way not obvious me. seems weird can't find mention of anywhere.

this best way come with, seems obtuse:

class productmultiselect extends component {     constructor(props) {         super(props)          this.state = {             selectedvalues: []         }          this.onchange = this.onchange.bind(this)     }      onchange (value) {          // update redux form         this.props.input.onchange(value)          const newvalues = value.map( product => product.value)          if (newvalues.length == 0 || newvalues.length < this.state.selectedvalues.length) {             const removedvalue = this.state.selectedvalues.filter(x => newvalues.indexof(x) < 0 );             this.setstate({selectedvalues: newvalues})         } else {             const newvalue = newvalues.filter(x => this.state.selectedvalues.indexof(x) < 0 );             this.setstate({selectedvalues: newvalues})         }     }      render() {         return (             <select                 {...this.props}                 value={this.props.input.value}                 multi                 onchange={(value) => this.onchange(value)}                 onblur={() => this.props.input.onblur(this.props.input.value)}                 options={this.props.options}                 classname='form-group'             />         )     } }  export default productmultiselect 

it depends on want access unselected values. i'm assuming unselected values part of previous state? if that's case, can access them in version of this.setstate accepts function instead of object. (pulled documentation). if values unselected part of previous state, can whatever you'd them inside of here.

this.setstate((prevstate, props) => ({   counter: prevstate.counter + props.increment })); 

reference here: https://facebook.github.io/react/docs/state-and-lifecycle.html#state-updates-may-be-asynchronous





wiki

Comments

Popular posts from this blog

elasticsearch - what is the equivalent data type for geo_point in hibernate search? -

firebase - How to wait value in Ionic 2 -

powershell - Invoke-WebRequest fails for a large file -