Giter Club home page Giter Club logo

Comments (13)

itsdouges avatar itsdouges commented on June 2, 2024 2

i'll create an example so we have something to talk about, give me a bit.

from rheostat.

ljharb avatar ljharb commented on June 2, 2024

"on change" suggests to me that it should fire whenever there's been any change at all; the source of that change is irrelevant.

from rheostat.

itsdouges avatar itsdouges commented on June 2, 2024

Well maybe, but that's not how controlled input components work in react.. if they did we'd get into infinite loops by default wouldn't we? 😬

from rheostat.

ljharb avatar ljharb commented on June 2, 2024

A controlled input wouldn't have the value change except via user action; can you provide a repro case where you're getting onChange otherwise?

from rheostat.

itsdouges avatar itsdouges commented on June 2, 2024

Sure I'll make a webpack bin real quick (...in a few hours, train is just getting into work, sorry!)

Also - I'm actually changing the value via user interaction (then updating state onChange), as well as updating the value programatically on a button press. Maybe that use case wasn't initially considered?

from rheostat.

ljharb avatar ljharb commented on June 2, 2024

"on a button press" is as a result of user interaction, why wouldn't that trigger onChange?

from rheostat.

itsdouges avatar itsdouges commented on June 2, 2024

@ljharb hey, made an example repo -> https://github.com/madou/rheostat-double-onchange

wanted to use webpack bin but it isn't working atm.

from the example - i would have thought rheostat wouldn't call onchange if i set the value outside of it. but it's calling it. whats your thoughts?

from rheostat.

goatslacker avatar goatslacker commented on June 2, 2024

Yup, it looks like onChange is called whenever values change. The documentation states that onChange is called when the values are "committed" which happens by drag, click, keyboard input, and props change.

We should maybe not do it when props change to your point of not having it trigger an infinite loop but I think that line is there for a reason.

Perhaps what we need is an event that fires only when the slider is changed in a non-programmatic way.

from rheostat.

itsdouges avatar itsdouges commented on June 2, 2024

hey! maybe.

i think the default expectation (well myself at least, haha) using controlled input components is it only gets triggered from the component itself trying to change. so i don't think it would be completely left field to make it do that.

breaking change though.

from rheostat.

intergalacticspacehighway avatar intergalacticspacehighway commented on June 2, 2024

@Madou Yes, I was expecting the same behavior as controlled inputs and it triggered infinite loop while setting values state programmatically.
I agree with the @goatslacker, we can add an event that only fires when the user interacts with the slider.

from rheostat.

nshelar avatar nshelar commented on June 2, 2024

Since onChange is called even when the props change, had to do a workaround as mentioned by @Madou. I second @goatslacker for adding an event that fires only when slider is changed by the user.

from rheostat.

jacobbuck avatar jacobbuck commented on June 2, 2024

I'm seeing the onChange getting called when the min/max props changing, but not the values. Perhaps the onChange should only call if values have changed from being outside min/max range 🤔

from rheostat.

neil-morrison44 avatar neil-morrison44 commented on June 2, 2024

We've also been dealing with this causing infinite loops, ended with a nextChangeIsReal flag to implement @Madou 's suggestion.
It feels like an unexpected thing for the component do to compared to other controlled components

from rheostat.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.