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.

bug: React IonRange gets into infinite render loop

See original GitHub issue

Bug Report

Ionic version:

[x] 5.0.7

Current behavior: I’m using the IonRange component with dualKnobs. When trying to set a default value and update state with onIonChange the parent component gets into an infinite render loop as soon as I update the range state.

Expected behavior: I should be able set the default value of the lower and upper knobs by setting the value prop of IonRange. This works, but as soon slide one of the knobs, the parent component repeatedly re-renders forever.

Steps to reproduce: Create a component with that renders an IonRange component and also useState. You can see an example here: https://stackblitz.com/edit/ionic-react-demo-tt4ytk?file=pages%2FHome.jsx

As soon as you adjust one of the knobs (and onIonChange is called), you will see that the component is rendered in a loop - console.log('render') is called repeatedly forever.

Related code:

const MyComponent = () => {
  const defaultValue = {lower: 40, upper: 70};
  const [range, setRange] = useState(defaultValue);
  
  console.log('render');

  return (
    <IonRange dualKnobs={true} min={0} max={100} value={{...defaultValue}} onIonChange={ e => setRange(e.detail.value) }>
      <IonLabel slot="start">{range.lower}</IonLabel>
      <IonLabel slot="end">{range.upper}</IonLabel>
    </IonRange>        
  );
};

Other information:

Ionic info:

Ionic:

   Ionic CLI       : 6.6.0 
   Ionic Framework : @ionic/react 5.0.7

Capacitor:

   Capacitor CLI   : 2.0.0
   @capacitor/core : 2.0.0

Utility:

   cordova-res : not installed
   native-run  : not installed

System:

   NodeJS : v12.16.1 
   npm    : 6.13.4
   OS     : macOS Catalina

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:4
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

5reactions
jamesopstadcommented, Jul 6, 2021

This still seems to be an issue and it’s quite a serious one. Are there any updates?

2reactions
CameronCTcommented, Dec 6, 2021

Odd that this hasn’t been fixed over a year later. The current work around is putting return false if the value matches your local state variable under onIonChange.

Read more comments on GitHub >

github_iconTop Results From Across the Web

bug: React IonRange gets into infinite render loop ... - GitHub
When React renders the IonRange component, it sets the value from the range state, which it's managing on its own. Inside IonRange the...
Read more >
React too many re renders infinite loop - Stack Overflow
I'm not sure why i'm getting this error, i'm just trying to make a button that inverts colors on hover, if you have...
Read more >
React - how to fix too many re-renders (infinite loop) error ...
Hello! Recently I was looking for a solution on how to update an object inside useState and got this error: \
Read more >
Ion-Slides: Mobile Touch Slider with Built-In & Custom Animation
Ion-Slides is a multi-section container which offers custom and built-in mobile touch slider animation effects. See how Ion-Slides works with iOS and ...
Read more >
[Solved]-How to resolve infinite loop error in reactjs?
[Solved]-How to resolve infinite loop error in reactjs?-Reactjs. Search. score:0. Accepted answer. const Modals = (props) => { const [validation ...
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