Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get MUI Slider value in onDragStop event

I want to fire an event onDragStop rather than onChange using a MUI Slider in my React app (so that the event fires fewer times). However, the documentation indicates that the onDragStop function signature only has the mouseevent: function(event: object) => void. So, the following works with onChange:

<Slider onChange={ (e, val) => this.props.update(e, control.id, val) }  />

However, this event doesn't have a second parameter val:

<Slider onDragStop={ (e, val) => this.props.update(e, control.id, val) }  />

How can I get the current value of the Slider in the onDragStop function? Note, I'm unable to use this, as it refers to the parent component.

like image 222
mike Avatar asked Nov 22 '17 16:11

mike


Video Answer


2 Answers

In a newer version of Material UI you could use:

<Slider
  onChange={} // for example updating a state value
  onChangeCommitted={} // for example fetching new data
/>
like image 102
Wannes Avatar answered Sep 19 '22 21:09

Wannes


Also ran into this problem! If you use a component inside a class, use both callbacks:

<Slider onChange={ (e, val) => this.val = val }  
        onDragStop={ (e) => this.props.update(e, control.id, this.val)
/>
like image 39
Masterstvo_ Avatar answered Sep 18 '22 21:09

Masterstvo_