@@ -318,32 +318,38 @@ class Downshift extends Component {
318318 return this . setState (
319319 state => {
320320 state = this . getState ( state )
321- stateToSet = isStateToSetFunction ? stateToSet ( state ) : stateToSet
321+ let newStateToSet = isStateToSetFunction
322+ ? stateToSet ( state )
323+ : stateToSet
322324
323325 // Your own function that could modify the state that will be set.
324- stateToSet = this . props . stateReducer ( state , stateToSet )
326+ newStateToSet = this . props . stateReducer ( state , newStateToSet )
325327
326328 // checks if an item is selected, regardless of if it's different from
327329 // what was selected before
328330 // used to determine if onSelect and onChange callbacks should be called
329- isItemSelected = stateToSet . hasOwnProperty ( 'selectedItem' )
331+ isItemSelected = newStateToSet . hasOwnProperty ( 'selectedItem' )
330332 // this keeps track of the object we want to call with setState
331333 const nextState = { }
332334 // this is just used to tell whether the state changed
333335 const nextFullState = { }
334336 // we need to call on change if the outside world is controlling any of our state
335337 // and we're trying to update that state. OR if the selection has changed and we're
336338 // trying to update the selection
337- if ( isItemSelected && stateToSet . selectedItem !== state . selectedItem ) {
338- onChangeArg = stateToSet . selectedItem
339+ if (
340+ isItemSelected &&
341+ newStateToSet . selectedItem !== state . selectedItem
342+ ) {
343+ onChangeArg = newStateToSet . selectedItem
339344 }
340- stateToSet . type = stateToSet . type || Downshift . stateChangeTypes . unknown
345+ newStateToSet . type =
346+ newStateToSet . type || Downshift . stateChangeTypes . unknown
341347
342- Object . keys ( stateToSet ) . forEach ( key => {
348+ Object . keys ( newStateToSet ) . forEach ( key => {
343349 // onStateChangeArg should only have the state that is
344350 // actually changing
345- if ( state [ key ] !== stateToSet [ key ] ) {
346- onStateChangeArg [ key ] = stateToSet [ key ]
351+ if ( state [ key ] !== newStateToSet [ key ] ) {
352+ onStateChangeArg [ key ] = newStateToSet [ key ]
347353 }
348354 // the type is useful for the onStateChangeArg
349355 // but we don't actually want to set it in internal state.
@@ -354,19 +360,22 @@ class Downshift extends Component {
354360 if ( key === 'type' ) {
355361 return
356362 }
357- nextFullState [ key ] = stateToSet [ key ]
363+ nextFullState [ key ] = newStateToSet [ key ]
358364 // if it's coming from props, then we don't care to set it internally
359365 if ( ! this . isControlledProp ( key ) ) {
360- nextState [ key ] = stateToSet [ key ]
366+ nextState [ key ] = newStateToSet [ key ]
361367 }
362368 } )
363369
364370 // if stateToSet is a function, then we weren't able to call onInputValueChange
365371 // earlier, so we'll call it now that we know what the inputValue state will be.
366- if ( isStateToSetFunction && stateToSet . hasOwnProperty ( 'inputValue' ) ) {
367- this . props . onInputValueChange ( stateToSet . inputValue , {
372+ if (
373+ isStateToSetFunction &&
374+ newStateToSet . hasOwnProperty ( 'inputValue' )
375+ ) {
376+ this . props . onInputValueChange ( newStateToSet . inputValue , {
368377 ...this . getStateAndHelpers ( ) ,
369- ...stateToSet ,
378+ ...newStateToSet ,
370379 } )
371380 }
372381
0 commit comments