useSyncExternalStoreShimClient.js — react Source File
Architecture documentation for useSyncExternalStoreShimClient.js, a javascript file in the react codebase. 2 imports, 1 dependents.
Entity Profile
Dependency Diagram
graph LR c8190e68_5a3d_877d_bd3a_2285ee34abfc["useSyncExternalStoreShimClient.js"] ac587885_e294_a1e9_b13f_5e7b920fdb42["react"] c8190e68_5a3d_877d_bd3a_2285ee34abfc --> ac587885_e294_a1e9_b13f_5e7b920fdb42 0ad79fb3_65a1_2b4a_c89f_a380efca26bf["objectIs"] c8190e68_5a3d_877d_bd3a_2285ee34abfc --> 0ad79fb3_65a1_2b4a_c89f_a380efca26bf 62252b8c_44a9_19ca_d235_2a34ff0286e7["useSyncExternalStoreShim.js"] 62252b8c_44a9_19ca_d235_2a34ff0286e7 --> c8190e68_5a3d_877d_bd3a_2285ee34abfc style c8190e68_5a3d_877d_bd3a_2285ee34abfc fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
*/
import * as React from 'react';
import is from 'shared/objectIs';
// Intentionally not using named imports because Rollup uses dynamic
// dispatch for CommonJS interop named imports.
const {useState, useEffect, useLayoutEffect, useDebugValue} = React;
let didWarnOld18Alpha = false;
let didWarnUncachedGetSnapshot = false;
// Disclaimer: This shim breaks many of the rules of React, and only works
// because of a very particular set of implementation details and assumptions
// -- change any one of them and it will break. The most important assumption
// is that updates are always synchronous, because concurrent rendering is
// only available in versions of React that also have a built-in
// useSyncExternalStore API. And we only use this shim when the built-in API
// does not exist.
//
// Do not assume that the clever hacks used by this hook also work in general.
// The point of this shim is to replace the need for hacks by other libraries.
export function useSyncExternalStore<T>(
subscribe: (() => void) => () => void,
getSnapshot: () => T,
// Note: The shim does not use getServerSnapshot, because pre-18 versions of
// React do not expose a way to check if we're hydrating. So users of the shim
// will need to track that themselves and return the correct value
// from `getSnapshot`.
getServerSnapshot?: () => T,
): T {
if (__DEV__) {
if (!didWarnOld18Alpha) {
if (React.startTransition !== undefined) {
didWarnOld18Alpha = true;
// Avoid transforming the `console.error` call as it would cause the built artifact
// to access React internals, which exist under different paths depending on the
// React version.
console['error'](
'You are using an outdated, pre-release alpha of React 18 that ' +
'does not support useSyncExternalStore. The ' +
'use-sync-external-store shim will not work correctly. Upgrade ' +
'to a newer pre-release.',
);
}
}
}
// Read the current snapshot from the store on every render. Again, this
// breaks the rules of React, and only works here because of specific
// implementation details, most importantly that updates are
// always synchronous.
const value = getSnapshot();
// ... (90 more lines)
Domain
Dependencies
- objectIs
- react
Source
Frequently Asked Questions
What does useSyncExternalStoreShimClient.js do?
useSyncExternalStoreShimClient.js is a source file in the react codebase, written in javascript. It belongs to the BabelCompiler domain.
What does useSyncExternalStoreShimClient.js depend on?
useSyncExternalStoreShimClient.js imports 2 module(s): objectIs, react.
What files import useSyncExternalStoreShimClient.js?
useSyncExternalStoreShimClient.js is imported by 1 file(s): useSyncExternalStoreShim.js.
Where is useSyncExternalStoreShimClient.js in the architecture?
useSyncExternalStoreShimClient.js is located at packages/use-sync-external-store/src/useSyncExternalStoreShimClient.js (domain: BabelCompiler, directory: packages/use-sync-external-store/src).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free