Deep runtime internals, memory models, distributed design, concurrency failure modes, and architectural decisions.
memoizedState/dependencies registry; consumers attach dependencies first-class lists pointing at context items.fiber.flags (PropagationNeeded-style) and walks from provider downward marking consumer fibers with an update lane — it does NOT scan the whole tree; cost is proportional to subscribers below the provider._currentValue via the pushed stack; nested providers shadow by push/pop ordering.propagateContextChange-era vs modern dependent-list traversal evolution.Semantics: Provider reads parent theme via useContext, shallow-merges prop override, provides merged result:
function ThemeProvider({theme: override, children}) {
const inherited = useContext(ThemeCtx);
const value = useMemo(() => ({...inherited, ...override}), [inherited, override]);
...
}
Pitfalls:
Idea: keep one source of truth OUTSIDE react (plain store); context carries only the store handle + version counter; a hook uses useSyncExternalStore against that store for slices:
const StoreCtx = createContext<Store>(null!);
export function useSelector<T>(sel:(s:S)=>T):T {
const store = useContext(StoreCtx);
return useSyncExternalStore(store.subscribe, () => sel(store.get()), () => sel(store.initial));
}
Why this wins: context updates ONLY when identity of store changes (never), so context-driven invalidation disappears; slice precision comes from external subscription machinery with built-in tearing protection. This hybrid is exactly how Zustand-context adapters work — explaining it proves systems fluency.
store.getState() as provider value during transitions can capture mixed epochs.
Tear-safe bridge rules: freeze snapshot per render pass, subscribe via useSyncExternalStore (its consistency check restarts inconsistent renders), never mutate snapshots in place.You've completed the 5 free sample questions. Get unrestricted lifetime access to every question, model answer, implementation challenge, and all 27+ technologies for a single payment.
₹399 India / $9 International · One-time settlement · Zero subscription