useSubscription.js — react Source File
Architecture documentation for useSubscription.js, a javascript file in the react codebase. 1 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR b3e8c530_5dba_ce6e_ff84_9502c75e27f1["useSubscription.js"] dd6bce81_f20c_6ef1_fe0d_89525ea33b93["shim"] b3e8c530_5dba_ce6e_ff84_9502c75e27f1 --> dd6bce81_f20c_6ef1_fe0d_89525ea33b93 style b3e8c530_5dba_ce6e_ff84_9502c75e27f1 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 {useSyncExternalStore} from 'use-sync-external-store/shim';
// Hook used for safely managing subscriptions in concurrent mode.
//
// In order to avoid removing and re-adding subscriptions each time this hook is called,
// the parameters passed to this hook should be memoized in some way–
// either by wrapping the entire params object with useMemo()
// or by wrapping the individual callbacks with useCallback().
export function useSubscription<Value>({
// (Synchronously) returns the current value of our subscription.
getCurrentValue,
// This function is passed an event handler to attach to the subscription.
// It should return an unsubscribe function that removes the handler.
subscribe,
}: {
getCurrentValue: () => Value,
subscribe: (callback: Function) => () => void,
}): Value {
return useSyncExternalStore(subscribe, getCurrentValue);
}
Dependencies
- shim
Source
Frequently Asked Questions
What does useSubscription.js do?
useSubscription.js is a source file in the react codebase, written in javascript.
What does useSubscription.js depend on?
useSubscription.js imports 1 module(s): shim.
Where is useSubscription.js in the architecture?
useSubscription.js is located at packages/use-subscription/src/useSubscription.js (directory: packages/use-subscription/src).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free