cefn / watchable

Repo for @watchable/store and supporting packages.
MIT License
5 stars 1 forks source link

Rethink state held in useSelected - may trigger unnecessary renders #39

Closed cefn closed 9 months ago

cefn commented 10 months ago

If the store or selector has been changed (as part of component props or state) this will have already triggered a re-render by React anyway.

At this point, the selected value can be derived from state, without also setting state and therefore triggering a re-render.

Perhaps the state held by useSelected (and used to force a re-render on change to selected) should not be the selected value itself. This is a derived value and doesn't need to re-render when the store or selector has changed, only when a store write has changed it independently of these two values.

Nevertheless it needs to have the 'means' of triggering a re-render when store state HAS caused the selected value to change.

cefn commented 9 months ago

Closed by https://github.com/cefn/watchable/pull/43