MCPcopy
hub / github.com/preactjs/preact / Child1

Function Child1

compat/test/browser/useSyncExternalStore.test.jsx:511–524  ·  view source on GitHub ↗
({ step })

Source from the content-addressed store, hash-verified

509 const getSnapshotB = () => store.getState().b;
510
511 function Child1({ step }) {
512 const value = useSyncExternalStore(store.subscribe, store.getState);
513 useLayoutEffect(() => {
514 if (step === 1) {
515 // Update B in a layout effect. This happens in the same commit
516 // that changed the getSnapshot in Child2. Child2's effects haven't
517 // fired yet, so it doesn't have access to the latest getSnapshot. So
518 // it can't use the getSnapshot to bail out.
519 Scheduler.log('Update B in commit phase');
520 store.set({ a: value.a, b: 2 });
521 }
522 }, [step]);
523 return null;
524 }
525
526 function Child2({ step }) {
527 const label = step === 0 ? 'A' : 'B';

Callers

nothing calls this directly

Calls 3

useSyncExternalStoreFunction · 0.90
useLayoutEffectFunction · 0.85
setMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…