Skip to content

Commit

Permalink
devtools: Don't display hook index of useContext (facebook#22200)
Browse files Browse the repository at this point in the history
  • Loading branch information
eps1lon authored and zhengjitf committed Apr 15, 2022
1 parent c582dea commit 889a180
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ function HookView({

let name = hook.name;
if (enableProfilerChangedHookIndices) {
if (!isCustomHook) {
if (hookID !== null) {
name = (
<>
<span className={styles.PrimitiveHookNumber}>{hookID + 1}</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@

import * as React from 'react';
import {
createContext,
forwardRef,
Fragment,
memo,
useCallback,
useContext,
useDebugValue,
useEffect,
useState,
Expand Down Expand Up @@ -64,8 +66,13 @@ function useDeepHookF() {
useDebugValue('useDeepHookF');
}

const ContextA = createContext('A');
const ContextB = createContext('B');

function FunctionWithHooks(props: any, ref: React$Ref<any>) {
const [count, updateCount] = useState(0);
// eslint-disable-next-line no-unused-vars
const contextValueA = useContext(ContextA);

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

// eslint-disable-next-line no-unused-vars
const contextValueB = useContext(ContextB);

// Verify deep nesting doesn't break
useDeepHookA();

Expand Down

0 comments on commit 889a180

Please sign in to comment.