question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Slider onChangeEnd being called multiple times

See original GitHub issue

Bug report

Describe the bug

I need to control my Slider and open a Popover as soon as the user finishes sliding it. To do so, I’ve created a state in my component that evaluates if the popover should be opened or not.

To make it work, I’ve added a function to onChangeEnd prop that updates my state, enabling the Popover to be displayed.

Since my Slider is controlled (I need to display it’s value elsewhere) I have an onChange function too, that updates another state (a Recoil state).

I’ve noticed that in this scenario, the Slider onChangeEnd is called multiple times.

To reproduce

You can check this sandbox and drag the slider. Open the console and see that for each time you finish dragging, we got a console log twice (instead of once)

Minimal reproduction

https://codesandbox.io/s/chakra-slider-onchangeend-multiple-executions-g7v0c

Expected behavior

The Slider component should be able to understand if the onChangeEnd was already called, and prevent from doing that twice.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:21 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
deluccacommented, Nov 28, 2020

For future reference my mistake was the following:

I was trying to set the popover state at the same level, or below, that the value of my progress slider state. So, that locked me into an infinite loop.

After lifting the popover state above (to the Recoil layer) all problems were fixed 😃

Thanks for your help guys!

1reaction
deluccacommented, Nov 28, 2020

Thanks 😃

In any case, I’ve followed your suggestion and moved the isOpen to the Recoil layer. I rewrote the entire component but now it is working as expected.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why does my React Slider call my function twice?
I am rendering a Chakra UI slider and line graph on my page. When I stop moving the slider, it should call a...
Read more >
Material UI Slider onChange firing many times on dragging ...
Whenever I drag the slider, it will fire multiple times between steps - ... It is called onChangeCommitted, so it only fires when...
Read more >
onChangeEnd property - Slider class - material library - Dart API
API docs for the onChangeEnd property from the Slider class, for the Dart programming ... Called when the user is done selecting a...
Read more >
onChangeEnd and onChangeStart methods in sfSlider
Is there any way to get a callback every time the user release the slider button? Like the " OnChangeEnd" method of "SfLinearGauge"....
Read more >
Explore Fluid Slider In Flutter - FlutterDevs
Use Flutter Fluid Slider Package To Create Beautiful Fluid Slider In Your ... onChangeEnd: This property is called when the user is done...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found