Calculated field does not update immediately when value updates
See original GitHub issueI tested a model with an array of items, a calculated field for the item-count, and a thunk that fetches items. The flow is like this:
- The initial value of
itemscontains 3 items - Therefore the initial value of the calculated
count= 3 - A
getItems()thunk fetches 200 additional items, then… - An
appendItems()action appends these toitems
When the items are appended, the <List> component re-renders, as expected.
However the count still reports only 3 items.
The <List> immediately re-renders again; with the correct count this time.
Here is the output of console.log({ count, items }) for each render…
List.js { count: 3, items: Array(3) }
List.js { count: 3, items: Array(203) }
List.js { count: 203, items: Array(203) }
This is not a serious problem since it re-renders correctly a few ms later. However the calculated value is incorrect in the first re-render, and there should only be a single re-render.
Issue Analytics
- State:
- Created 4 years ago
- Comments:8 (8 by maintainers)
Top Results From Across the Web
Calculated Field not updating based on field in calculation
I have a numeric field in a table, the Calculation is set "Auto Enter Calculation replaces existing value". The calculation is made up...
Read more >Calculation Fields Not Updating (JavaScript) - Acrobat Answers
I have several fields that update the total price "live" but I have one field that went a number is entered, it updates...
Read more >The formula is not updating when I change a value in a cell.
Please go to Formulas >> Calculation >> Calculation Options, and change it to Automatic. I hope this helps you. Regards. 0 Likes.
Read more >calculated columns are not updating after adding new data
I have a calculated field, there is no way I can update them with new data ... For example to calculate total profit,...
Read more >list calculations do not update when values are changed if ...
list calculations do not update when values are changed if using a comma as a decimal separator, so values are wrong - values...
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 Free
Top 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

ACTUALLY your sandbox shows the same resulte. You just aren’t noticing the 2nd re-render. I added some console.log output to your sample…
This is what the console shows for each of the 3 renders. Note that in the 2nd render the ‘count’ is out of sync with the number of items.
That’s cool. Simpler and simpler.