Setting Start Date and End Date with onChange lead to infinit reRender
See original GitHub issueHello , First Thank you so much for the great Job , i tried to use the DateRangePicker and set startDate and EndDate from my redux, or even new Date() just for test , but it always fires the onChange on component mounting which lead to infinit reRender and Crash of the app, here what i did :
<RangeDatePicker
startDate={new Date()}
endDate={null}
onChange={(startDate, endDate) => props.handleDatesChange(startDate, endDate)}
minDate={new Date()}
maxDate={new Date(2022, 0, 1)}
dateFormat="dddd D MMM"
monthFormat="MMM YYYY"
startDatePlaceholder={<Translate tKey="start_date" />}
endDatePlaceholder={<Translate tKey="end_date" />}
disabled={false}
className="my-own-class-name"
startWeekDay="monday"
/>
To reproduce the issue use startDate
and endDate
from redux store and the onChange
dispatch an action
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
Why does setState in the body of the component cause an ...
In your case , You Have SetState in the body of the Component.. So it will rerender and Cause an Infinite Loop.. If...
Read more >3 ways to cause an infinite loop in React - Alex Sidorenko
By executing a function before setting a handler, you update a state inside the render, which causes an infinite loop. State updates →...
Read more >When does React re-render components? - Felix Gerschau
Scheduling a render means that this doesn't happen immediately. React will try to find the best moment for this. Changing the state means...
Read more >How to solve too many re-renders error in ReactJS?
Use React shouldComponentUpdate: React shouldComponentUpdate is a method for optimizing performance, which tells React to stop re-rendering a ...
Read more >Too many re-renders. React limits the number ... - Datainfinities
The above code will throw an error because we are trying to change the name setName("John"); in the main body of the component....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@kouloughli-hemza Hi, I have fixed this issue, please check.
it works great now , thank you lot