ReactHooks.js — react Source File
Architecture documentation for ReactHooks.js, a javascript file in the react codebase. 4 imports, 5 dependents.
Entity Profile
Dependency Diagram
graph LR 902331a7_1a5c_5543_eee5_236867f259f4["ReactHooks.js"] 42892443_e223_3da0_aeb9_e1b32a408fb0["ReactInternalTypes"] 902331a7_1a5c_5543_eee5_236867f259f4 --> 42892443_e223_3da0_aeb9_e1b32a408fb0 d8f20c67_f5fa_0f0a_c967_c41fd9ffce07["ReactTypes"] 902331a7_1a5c_5543_eee5_236867f259f4 --> d8f20c67_f5fa_0f0a_c967_c41fd9ffce07 e1e1de60_2be4_0643_45fb_e2c306735427["ReactSymbols"] 902331a7_1a5c_5543_eee5_236867f259f4 --> e1e1de60_2be4_0643_45fb_e2c306735427 1c5695a6_6806_ba54_2074_efc779e66da4["ReactSharedInternals"] 902331a7_1a5c_5543_eee5_236867f259f4 --> 1c5695a6_6806_ba54_2074_efc779e66da4 ffdf54f0_7e34_f1e9_1504_9dbadb0fbac5["ReactClient.js"] ffdf54f0_7e34_f1e9_1504_9dbadb0fbac5 --> 902331a7_1a5c_5543_eee5_236867f259f4 a893f937_cfbc_33f8_94ec_23cb5000691e["ReactServer.experimental.development.js"] a893f937_cfbc_33f8_94ec_23cb5000691e --> 902331a7_1a5c_5543_eee5_236867f259f4 8510e4c8_924c_b1b8_d0a0_11cb99b570c0["ReactServer.experimental.js"] 8510e4c8_924c_b1b8_d0a0_11cb99b570c0 --> 902331a7_1a5c_5543_eee5_236867f259f4 6274036e_add3_9702_84fb_266b97b7660a["ReactServer.fb.js"] 6274036e_add3_9702_84fb_266b97b7660a --> 902331a7_1a5c_5543_eee5_236867f259f4 a86f40a1_cfab_7bca_7368_f11f9ee52c80["ReactServer.js"] a86f40a1_cfab_7bca_7368_f11f9ee52c80 --> 902331a7_1a5c_5543_eee5_236867f259f4 style 902331a7_1a5c_5543_eee5_236867f259f4 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 type {Dispatcher} from 'react-reconciler/src/ReactInternalTypes';
import type {
ReactContext,
StartTransitionOptions,
Usable,
Awaited,
} from 'shared/ReactTypes';
import {REACT_CONSUMER_TYPE} from 'shared/ReactSymbols';
import ReactSharedInternals from 'shared/ReactSharedInternals';
type BasicStateAction<S> = (S => S) | S;
type Dispatch<A> = A => void;
function resolveDispatcher() {
const dispatcher = ReactSharedInternals.H;
if (__DEV__) {
if (dispatcher === null) {
console.error(
'Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for' +
' one of the following reasons:\n' +
'1. You might have mismatching versions of React and the renderer (such as React DOM)\n' +
'2. You might be breaking the Rules of Hooks\n' +
'3. You might have more than one copy of React in the same app\n' +
'See https://react.dev/link/invalid-hook-call for tips about how to debug and fix this problem.',
);
}
}
// Will result in a null access error if accessed outside render phase. We
// intentionally don't throw our own error because this is in a hot path.
// Also helps ensure this is inlined.
return ((dispatcher: any): Dispatcher);
}
export function getCacheForType<T>(resourceType: () => T): T {
const dispatcher = ReactSharedInternals.A;
if (!dispatcher) {
// If there is no dispatcher, then we treat this as not being cached.
return resourceType();
}
return dispatcher.getCacheForType(resourceType);
}
export function useContext<T>(Context: ReactContext<T>): T {
const dispatcher = resolveDispatcher();
if (__DEV__) {
if (Context.$$typeof === REACT_CONSUMER_TYPE) {
console.error(
'Calling useContext(Context.Consumer) is not supported and will cause bugs. ' +
'Did you mean to call useContext(Context) instead?',
);
// ... (182 more lines)
Domain
Dependencies
- ReactInternalTypes
- ReactSharedInternals
- ReactSymbols
- ReactTypes
Imported By
Source
Frequently Asked Questions
What does ReactHooks.js do?
ReactHooks.js is a source file in the react codebase, written in javascript. It belongs to the BabelCompiler domain.
What does ReactHooks.js depend on?
ReactHooks.js imports 4 module(s): ReactInternalTypes, ReactSharedInternals, ReactSymbols, ReactTypes.
What files import ReactHooks.js?
ReactHooks.js is imported by 5 file(s): ReactClient.js, ReactServer.experimental.development.js, ReactServer.experimental.js, ReactServer.fb.js, ReactServer.js.
Where is ReactHooks.js in the architecture?
ReactHooks.js is located at packages/react/src/ReactHooks.js (domain: BabelCompiler, directory: packages/react/src).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free