Skip to content

Commit 5037b4e

Browse files
authored
devtools: Don't display hook index of useContext (#22200)
1 parent 46a0f05 commit 5037b4e

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

packages/react-devtools-shared/src/devtools/views/Components/InspectedElementHooksTree.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ function HookView({
222222

223223
let name = hook.name;
224224
if (enableProfilerChangedHookIndices) {
225-
if (!isCustomHook) {
225+
if (hookID !== null) {
226226
name = (
227227
<>
228228
<span className={styles.PrimitiveHookNumber}>{hookID + 1}</span>

packages/react-devtools-shell/src/app/InspectableElements/CustomHooks.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@
99

1010
import * as React from 'react';
1111
import {
12+
createContext,
1213
forwardRef,
1314
Fragment,
1415
memo,
1516
useCallback,
17+
useContext,
1618
useDebugValue,
1719
useEffect,
1820
useState,
@@ -64,8 +66,13 @@ function useDeepHookF() {
6466
useDebugValue('useDeepHookF');
6567
}
6668

69+
const ContextA = createContext('A');
70+
const ContextB = createContext('B');
71+
6772
function FunctionWithHooks(props: any, ref: React$Ref<any>) {
6873
const [count, updateCount] = useState(0);
74+
// eslint-disable-next-line no-unused-vars
75+
const contextValueA = useContext(ContextA);
6976

7077
// eslint-disable-next-line no-unused-vars
7178
const [_, __] = useState(object);
@@ -85,6 +92,9 @@ function FunctionWithHooks(props: any, ref: React$Ref<any>) {
8592
// Tests nested custom hooks
8693
useNestedOuterHook();
8794

95+
// eslint-disable-next-line no-unused-vars
96+
const contextValueB = useContext(ContextB);
97+
8898
// Verify deep nesting doesn't break
8999
useDeepHookA();
90100

0 commit comments

Comments
 (0)