useSyncExternalStoreWithSelector.js — react Source File
Architecture documentation for useSyncExternalStoreWithSelector.js, a javascript file in the react codebase. 3 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR dd10bb36_577c_6fb4_13b7_b74cf6962b86["useSyncExternalStoreWithSelector.js"] ac587885_e294_a1e9_b13f_5e7b920fdb42["react"] dd10bb36_577c_6fb4_13b7_b74cf6962b86 --> ac587885_e294_a1e9_b13f_5e7b920fdb42 0ad79fb3_65a1_2b4a_c89f_a380efca26bf["objectIs"] dd10bb36_577c_6fb4_13b7_b74cf6962b86 --> 0ad79fb3_65a1_2b4a_c89f_a380efca26bf 6fead1f1_0d1d_a2ed_4add_afccc546887f["useSyncExternalStore"] dd10bb36_577c_6fb4_13b7_b74cf6962b86 --> 6fead1f1_0d1d_a2ed_4add_afccc546887f style dd10bb36_577c_6fb4_13b7_b74cf6962b86 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';
import {useSyncExternalStore} from 'use-sync-external-store/src/useSyncExternalStore';
// Intentionally not using named imports because Rollup uses dynamic dispatch
// for CommonJS interop.
const {useRef, useEffect, useMemo, useDebugValue} = React;
// Same as useSyncExternalStore, but supports selector and isEqual arguments.
export function useSyncExternalStoreWithSelector<Snapshot, Selection>(
subscribe: (() => void) => () => void,
getSnapshot: () => Snapshot,
getServerSnapshot: void | null | (() => Snapshot),
selector: (snapshot: Snapshot) => Selection,
isEqual?: (a: Selection, b: Selection) => boolean,
): Selection {
type Inst =
| {
hasValue: true,
value: Selection,
}
| {
hasValue: false,
value: null,
};
// Use this to track the rendered snapshot.
const instRef = useRef<Inst | null>(null);
let inst: Inst;
if (instRef.current === null) {
inst = {
hasValue: false,
value: null,
};
instRef.current = inst;
} else {
inst = instRef.current;
}
const [getSelection, getServerSelection] = useMemo(() => {
// Track the memoized state using closure variables that are local to this
// memoized instance of a getSnapshot function. Intentionally not using a
// useRef hook, because that state would be shared across all concurrent
// copies of the hook/component.
let hasMemo = false;
let memoizedSnapshot;
let memoizedSelection: Selection;
const memoizedSelector = (nextSnapshot: Snapshot) => {
if (!hasMemo) {
// The first time the hook is called, there is no memoized result.
hasMemo = true;
// ... (73 more lines)
Dependencies
- objectIs
- react
- useSyncExternalStore
Source
Frequently Asked Questions
What does useSyncExternalStoreWithSelector.js do?
useSyncExternalStoreWithSelector.js is a source file in the react codebase, written in javascript.
What does useSyncExternalStoreWithSelector.js depend on?
useSyncExternalStoreWithSelector.js imports 3 module(s): objectIs, react, useSyncExternalStore.
Where is useSyncExternalStoreWithSelector.js in the architecture?
useSyncExternalStoreWithSelector.js is located at packages/use-sync-external-store/src/useSyncExternalStoreWithSelector.js (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