pmndrs / jotai

👻 Primitive and flexible state management for React

Home Page:https://jotai.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Atoms sometimes cause updates to dependencies even when their value remains the same

MasonD opened this issue · comments

Summary

As per discussion with Daishi in the poimandres discord. In certain atom configurations, a derived atom will cause its dependencies to recalculate even if its value is identical to its previous value. It seems to be when

  • a derived atom A which we expect to keep the same
  • is used by another derived atom B
  • which is further used by another derived atom C which has other dependencies that change at the same time as A's dependencies.

This causes B to recalculate even though A's value remains the same

Link to reproduction

https://codesandbox.io/s/atomstate-d-changes-vz9p5f?file=/src/App.tsx