useSyncExternalStore: The Right Way to Subscribe to External State

Hands-on practice for this lecture. Work through the exercises and quizzes to reinforce what you've learned.

1

Exercise 1 of 1

useSyncExternalStore Quiz

Four questions on useSyncExternalStore — what getSnapshot must return, why subscribe needs a cleanup, the tearing problem, and when getServerSnapshot is required.

1
const count = useSyncExternalStore(
  subscribe,
  getSnapshot,
  getServerSnapshot
);

What does getSnapshot need to return?

2
function subscribe(listener) {
  store.listeners.push(listener);
  // missing something
}

What must subscribe return?

3

What problem does useSyncExternalStore solve that useState does not?

4

When is getServerSnapshot required?

0/4 answered

Practice: useSyncExternalStore: The Right Way to Subscribe to External State — Interactive Exercises | Durgesh Rai