devtools: Don't display hook index of useContext (#22200)

This commit is contained in:
Sebastian Silbermann 2021-08-30 21:44:12 +02:00 committed by GitHub
parent 46a0f050aa
commit 5037b4e2e6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 1 deletions

View File

@ -222,7 +222,7 @@ function HookView({
let name = hook.name; let name = hook.name;
if (enableProfilerChangedHookIndices) { if (enableProfilerChangedHookIndices) {
if (!isCustomHook) { if (hookID !== null) {
name = ( name = (
<> <>
<span className={styles.PrimitiveHookNumber}>{hookID + 1}</span> <span className={styles.PrimitiveHookNumber}>{hookID + 1}</span>

View File

@ -9,10 +9,12 @@
import * as React from 'react'; import * as React from 'react';
import { import {
createContext,
forwardRef, forwardRef,
Fragment, Fragment,
memo, memo,
useCallback, useCallback,
useContext,
useDebugValue, useDebugValue,
useEffect, useEffect,
useState, useState,
@ -64,8 +66,13 @@ function useDeepHookF() {
useDebugValue('useDeepHookF'); useDebugValue('useDeepHookF');
} }
const ContextA = createContext('A');
const ContextB = createContext('B');
function FunctionWithHooks(props: any, ref: React$Ref<any>) { function FunctionWithHooks(props: any, ref: React$Ref<any>) {
const [count, updateCount] = useState(0); const [count, updateCount] = useState(0);
// eslint-disable-next-line no-unused-vars
const contextValueA = useContext(ContextA);
// eslint-disable-next-line no-unused-vars // eslint-disable-next-line no-unused-vars
const [_, __] = useState(object); const [_, __] = useState(object);
@ -85,6 +92,9 @@ function FunctionWithHooks(props: any, ref: React$Ref<any>) {
// Tests nested custom hooks // Tests nested custom hooks
useNestedOuterHook(); useNestedOuterHook();
// eslint-disable-next-line no-unused-vars
const contextValueB = useContext(ContextB);
// Verify deep nesting doesn't break // Verify deep nesting doesn't break
useDeepHookA(); useDeepHookA();