State Management · Senior · Question 2 of 75
What's wrong with this getSnapshot?
useSyncExternalStore(subscribe, () => ({ items: store.items }));- ✓Correct answer: It returns a new object each call, so React sees endless changes and loops
- 2
getSnapshotmust be async - 3Snapshots can't contain arrays
Explanation
React calls getSnapshot repeatedly and compares results with Object.is; a fresh object means "changed" every time, causing infinite re-renders. Return a cached/immutable value from the store (or a primitive).