mirror of
https://github.com/facebook/react.git
synced 2026-11-18 20:15:56 +00:00
Inspectable complex hook values
This commit is contained in:
1 parent
47a5fd59cb
commit
0008bb00d7
4 files changed
+84
-24
No files matched your search
@@ -2,6 +2,7 @@
|
||||
|
||||
import React from 'react';
|
||||
import { getMetaValueLabel } from './utils';
|
||||
import { KeyValue } from './InspectedElementTree';
|
||||
import styles from './HooksTree.css';
|
||||
|
||||
import type { HooksNode, HooksTree } from 'src/backend/types';
|
||||
@@ -34,31 +35,67 @@ function HooksNodeView({ hooksNode }: { hooksNode: HooksNode }) {
|
||||
|
||||
const isCustomHook = subHooks.length > 0;
|
||||
|
||||
// Format data for display to mimic the props/state/context for now.
|
||||
const type = typeof value;
|
||||
|
||||
let displayValue;
|
||||
if (isCustomHook && value === undefined) {
|
||||
displayValue = null;
|
||||
} else if (
|
||||
type === 'number' ||
|
||||
type === 'string' ||
|
||||
type === 'boolean' ||
|
||||
value == null
|
||||
) {
|
||||
let isComplexDisplayValue = false;
|
||||
|
||||
// Format data for display to mimic the props/state/context for now.
|
||||
if (type === 'number' || type === 'string' || type === 'boolean') {
|
||||
displayValue = value;
|
||||
} else {
|
||||
displayValue = getMetaValueLabel(value);
|
||||
} else if (value === null) {
|
||||
displayValue = 'null';
|
||||
} else if (value === undefined) {
|
||||
displayValue = null;
|
||||
} else if (Array.isArray(value)) {
|
||||
isComplexDisplayValue = true;
|
||||
displayValue = 'Array';
|
||||
} else if (type === 'object') {
|
||||
isComplexDisplayValue = true;
|
||||
displayValue = 'Object';
|
||||
}
|
||||
|
||||
return (
|
||||
<div className={styles.HooksNode}>
|
||||
<div className={styles.NameValueRow}>
|
||||
<span className={styles.Name}>{name}: </span> {/* $FlowFixMe */}
|
||||
<span className={styles.Value}>{displayValue}</span>
|
||||
</div>
|
||||
<InnerHooksTreeView hooksTree={subHooks} />
|
||||
</div>
|
||||
);
|
||||
if (isCustomHook) {
|
||||
if (isComplexDisplayValue) {
|
||||
return (
|
||||
<div className={styles.HooksNode}>
|
||||
<div className={styles.NameValueRow}>
|
||||
<span className={styles.Name}>{name}: </span>
|
||||
</div>
|
||||
<KeyValue depth={1} name="DebugValue" value={value} />
|
||||
<InnerHooksTreeView hooksTree={subHooks} />
|
||||
</div>
|
||||
);
|
||||
} else {
|
||||
return (
|
||||
<div className={styles.HooksNode}>
|
||||
<div className={styles.NameValueRow}>
|
||||
<span className={styles.Name}>{name}: </span> {/* $FlowFixMe */}
|
||||
<span className={styles.Value}>{displayValue}</span>
|
||||
</div>
|
||||
<InnerHooksTreeView hooksTree={subHooks} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
} else {
|
||||
if (isComplexDisplayValue) {
|
||||
return (
|
||||
<div className={styles.HooksNode}>
|
||||
<KeyValue depth={0} name={name} value={value} />
|
||||
</div>
|
||||
);
|
||||
} else {
|
||||
return (
|
||||
<div className={styles.HooksNode}>
|
||||
<div className={styles.NameValueRow}>
|
||||
<span className={styles.Name}>{name}: </span>
|
||||
{/* $FlowFixMe */}
|
||||
<span className={styles.Value}>{displayValue}</span>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// $FlowFixMe
|
||||
|
||||
Reference in new issue
Block a user