State Management · Senior · Question 2 of 75

What's wrong with this getSnapshot?

useSyncExternalStore(subscribe, () => ({ items: store.items }));

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).

Further reading

Problem with a question

State Management · Senior · question 2

Test yourself

Take the State Management · Senior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz