Closed extrange closed 1 year ago
I think I'm seeing the same thing but with useEffect.
Hi!
Because SyncedStore uses observables, the actual array (state.todos) doesn't change if a value is added or removed.
I think in this cause it should work without the useMemo
, and the component will automatically rerender when the data has changed
Thanks!
I notice that re-renders happen when subscribing to a property of an object in an array, e.g. when a component uses state.todos[0].name
, if state.todos.push({name: 'new todo'})
is called elsewhere, the component will still rerender. This happens even if the component is wrapped in React.memo
.
Not sure if this is a bug or I am doing something wrong?
An example: clicking on 'Add Todo' causes the the component displaying the first todo to rerender, even though this should only happen when its title is modified.
It seems that using the state returned by
useSyncedStore
in a dependency array does not trigger a recalculation of memoized values.For the following code:
When the 'Add 1' button is clicked, the 'Sum' doesn't update.
CodeSandbox