0

I have TestStore and observable property fields.

When I click to any name, i call action changeOneName and change some object inside fields. Computed getter hasError called again and i see console.log("hasError computed");

Why don't I see console.log("valueFields computed"); second time after changing name to 'ErrorName'?

https://codesandbox.io/s/vibrant-lumiere-cv2tp?file=/src/TestStore.js

KAVA
  • 197
  • 1
  • 4
  • 16

1 Answers1

1

You only changed name property of the object, not the object itself. And Object.values only dereferences direct values (objects) of your fields object, not the inner things, like name. So computed don't need to rerun because things that were referenced in that computed didn't change.

hasError did rerun because you actually dereference name property inside of it, so when name changes it reruns.

Hope it makes sense.

Danila
  • 15,606
  • 2
  • 35
  • 67
  • 1
    Rerender happens because your whole App component is `observer` (which is more or less the same as `computed`, but for React components) and you dereference `name` inside its render. Component essentially subscribes for changes to every field you dereference inside of the render (inside of function basically). – Danila Jan 16 '22 at 00:44