← آزمایش‌ها

useSyncExternalStore Custom Hook Sandbox

This sandbox demonstrates a custom implementation of the useSyncExternalStore hook, next to the same counters kept in a shared React context.

useSyncExternalStoreCustom

+1 re-renders only that counter.

counter1: 1 · render #1

counter2: 1 · render #1

widget[counter1]: 1 · render #1

  • Bug 1 remounts the counters while an earlier sibling's effect adds 10 to counter1. The row keeps the old number until the next +1.
  • Bug 2 points the widget at the other counter. Its number stays behind (give the counters different values first).

useContext

+1 re-renders every counter: they share one context value.

context[counter1]: 1 · render #1

context[counter2]: 1 · render #1