diff --git a/shells/dev/app/InspectableElements/CustomHooks.js b/shells/dev/app/InspectableElements/CustomHooks.js index 7e0b318453..d85528eccc 100644 --- a/shells/dev/app/InspectableElements/CustomHooks.js +++ b/shells/dev/app/InspectableElements/CustomHooks.js @@ -11,6 +11,16 @@ import React, { useState, } from 'react'; +const object = { + string: 'abc', + number: 123, + boolean: true, + null: null, + undefined: undefined, + array: ['a', 'b', 'c'], + object: { foo: 1, bar: 2, baz: 3 }, +}; + function useNestedInnerHook() { return useState(123); } @@ -18,12 +28,20 @@ function useNestedOuterHook() { return useNestedInnerHook(); } +function useCustomObject() { + useDebugValue(object); + return useState(123); +} + function FunctionWithHooks(props: any, ref: React$Ref) { const [count, updateCount] = useState(0); + const [_, __] = useState(object); // Custom hook with a custom debug label const debouncedCount = useDebounce(count, 1000); + useCustomObject(); + const onClick = useCallback( function onClick() { updateCount(count + 1); diff --git a/src/devtools/views/HooksTree.js b/src/devtools/views/HooksTree.js index f2ec250820..3e6c6a898e 100644 --- a/src/devtools/views/HooksTree.js +++ b/src/devtools/views/HooksTree.js @@ -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 ( -
-
- {name}: {/* $FlowFixMe */} - {displayValue} -
- -
- ); + if (isCustomHook) { + if (isComplexDisplayValue) { + return ( +
+
+ {name}: +
+ + +
+ ); + } else { + return ( +
+
+ {name}: {/* $FlowFixMe */} + {displayValue} +
+ +
+ ); + } + } else { + if (isComplexDisplayValue) { + return ( +
+ +
+ ); + } else { + return ( +
+
+ {name}: + {/* $FlowFixMe */} + {displayValue} +
+
+ ); + } + } } // $FlowFixMe diff --git a/src/devtools/views/InspectedElementTree.js b/src/devtools/views/InspectedElementTree.js index c83e6b8418..b79fa52f18 100644 --- a/src/devtools/views/InspectedElementTree.js +++ b/src/devtools/views/InspectedElementTree.js @@ -47,7 +47,7 @@ type KeyValueProps = {| value: any, |}; -function KeyValue({ depth, name, value }: KeyValueProps) { +export function KeyValue({ depth, name, value }: KeyValueProps) { const dataType = typeof value; const isSimpleType = dataType === 'number' || @@ -64,6 +64,10 @@ function KeyValue({ depth, name, value }: KeyValueProps) { displayValue = `"${value}"`; } else if (dataType === 'boolean') { displayValue = value ? 'true' : 'false'; + } else if (value === null) { + displayValue = 'null'; + } else if (value === undefined) { + displayValue = 'undefined'; } children = ( @@ -99,6 +103,7 @@ function KeyValue({ depth, name, value }: KeyValueProps) { ); } else { + // $FlowFixMe children = Object.entries(value).map(([name, value]) => ( )); diff --git a/src/devtools/views/SettingsContext.js b/src/devtools/views/SettingsContext.js index 83a429c1b5..2da5bc5822 100644 --- a/src/devtools/views/SettingsContext.js +++ b/src/devtools/views/SettingsContext.js @@ -132,13 +132,13 @@ function updateThemeVariables(theme: Theme): void { updateStyleHelper(theme, 'color-dim'); updateStyleHelper(theme, 'color-dimmer'); updateStyleHelper(theme, 'color-dimmest'); - updateStyleHelper(theme, 'color-search-match'); - updateStyleHelper(theme, 'color-search-match-current'); - updateStyleHelper(theme, 'color-text-color'); updateStyleHelper(theme, 'color-jsx-arrow-brackets'); updateStyleHelper(theme, 'color-jsx-arrow-brackets-inverted'); updateStyleHelper(theme, 'color-tree-node-selected'); updateStyleHelper(theme, 'color-tree-node-hover'); + updateStyleHelper(theme, 'color-search-match'); + updateStyleHelper(theme, 'color-search-match-current'); + updateStyleHelper(theme, 'color-text-color'); } export { SettingsContext, SettingsContextController };