@@ -84,8 +84,11 @@ export class Slider extends Component {
84
84
this . setValue ( val , triggeredByUser , i ) ;
85
85
positions [ i ] = this . determinePosition ( val ) ;
86
86
} ) ;
87
- this . setState ( {
88
- position : positions ,
87
+ this . setState ( ( prevState ) => {
88
+ const positions = [ ...prevState . position ] ;
89
+ return {
90
+ position : positions ,
91
+ } ;
89
92
} ) ;
90
93
} else {
91
94
this . setValue ( value , triggeredByUser ) ;
@@ -211,11 +214,13 @@ export class Slider extends Component {
211
214
212
215
setValuePosition ( value , triggeredByUser , knobIndex ) {
213
216
if ( this . props . multiple ) {
214
- const positions = [ ...this . state . position ] ;
215
- positions [ knobIndex ] = this . determinePosition ( value ) ;
216
217
this . setValue ( value , triggeredByUser , knobIndex ) ;
217
- this . setState ( {
218
- position : positions ,
218
+ this . setState ( ( prevState ) => {
219
+ const positions = [ ...prevState . position ] ;
220
+ positions [ knobIndex ] = this . determinePosition ( value ) ;
221
+ return {
222
+ position : positions ,
223
+ } ;
219
224
} ) ;
220
225
} else {
221
226
this . setValue ( value , triggeredByUser ) ;
@@ -227,10 +232,12 @@ export class Slider extends Component {
227
232
228
233
setPosition ( position , knobIndex ) {
229
234
if ( this . props . multiple ) {
230
- const newPosition = [ ...this . state . position ] ;
231
- newPosition [ knobIndex ] = position ;
232
- this . setState ( {
233
- position : newPosition ,
235
+ this . setState ( ( prevState ) => {
236
+ const newPosition = [ ...prevState . position ] ;
237
+ newPosition [ knobIndex ] = position ;
238
+ return {
239
+ position : newPosition ,
240
+ } ;
234
241
} ) ;
235
242
} else {
236
243
this . setState ( {
0 commit comments