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.

Calculated field does not update immediately when value updates

See original GitHub issue

I 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 items contains 3 items
  • Therefore the initial value of the calculated count = 3
  • A getItems() thunk fetches 200 additional items, then…
  • An appendItems() action appends these to items

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:closed
  • Created 4 years ago
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
allprocommented, Jul 4, 2019

I am not seeing the same behaviour at all, even in different component trees.

See this sandbox example where I “fetch” 2000 items even.

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.

Object {items: Array[0], count: 0}
Object {items: Array[2000], count: 0}
Object {items: Array[2000], count: 2000}
0reactions
allprocommented, Jul 5, 2019

Nice side effect of this is that we no longer need to declare dependencies on the useStoreState hook.

That’s cool. Simpler and simpler.

Read more comments on GitHub >

github_iconTop 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 >

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