From 066b762583a71e91abd17df27c0b7453e16ad4b1 Mon Sep 17 00:00:00 2001 From: Brian Vaughn Date: Mon, 23 Sep 2019 11:24:03 -0700 Subject: [PATCH 1/2] Fixed a regression in hooks editor from a recent EditableValue change --- .../src/devtools/views/Components/EditableValue.js | 2 -- .../src/devtools/views/Components/HooksTree.js | 3 +-- .../src/devtools/views/Components/KeyValue.js | 3 +-- 3 files changed, 2 insertions(+), 6 deletions(-) diff --git a/packages/react-devtools-shared/src/devtools/views/Components/EditableValue.js b/packages/react-devtools-shared/src/devtools/views/Components/EditableValue.js index c196a8d83b74e..a0429bf8d37de 100644 --- a/packages/react-devtools-shared/src/devtools/views/Components/EditableValue.js +++ b/packages/react-devtools-shared/src/devtools/views/Components/EditableValue.js @@ -17,7 +17,6 @@ type OverrideValueFn = (path: Array, value: any) => void; type EditableValueProps = {| className?: string, - dataType: string, initialValue: any, overrideValueFn: OverrideValueFn, path: Array, @@ -25,7 +24,6 @@ type EditableValueProps = {| export default function EditableValue({ className = '', - dataType, initialValue, overrideValueFn, path, diff --git a/packages/react-devtools-shared/src/devtools/views/Components/HooksTree.js b/packages/react-devtools-shared/src/devtools/views/Components/HooksTree.js index 2fd4f95cbdb4f..ce0be7c47a1ef 100644 --- a/packages/react-devtools-shared/src/devtools/views/Components/HooksTree.js +++ b/packages/react-devtools-shared/src/devtools/views/Components/HooksTree.js @@ -270,10 +270,9 @@ function HookView({canEditHooks, hook, id, inspectPath, path}: HookViewProps) { {typeof overrideValueFn === 'function' ? ( ) : ( // $FlowFixMe Cannot create span element because in property children diff --git a/packages/react-devtools-shared/src/devtools/views/Components/KeyValue.js b/packages/react-devtools-shared/src/devtools/views/Components/KeyValue.js index e05a35fc57a7f..9e82eefa426fb 100644 --- a/packages/react-devtools-shared/src/devtools/views/Components/KeyValue.js +++ b/packages/react-devtools-shared/src/devtools/views/Components/KeyValue.js @@ -102,10 +102,9 @@ export default function KeyValue({ {isEditable ? ( ) : ( {displayValue} From c7e03b5e1d30218dc2aad047c242354337940f78 Mon Sep 17 00:00:00 2001 From: Brian Vaughn Date: Mon, 23 Sep 2019 11:39:44 -0700 Subject: [PATCH 2/2] Fixed a reset/state bug in useEditableValue() hook and removed unnecessary useMemo() --- .../src/devtools/views/hooks.js | 40 ++++++++----------- 1 file changed, 17 insertions(+), 23 deletions(-) diff --git a/packages/react-devtools-shared/src/devtools/views/hooks.js b/packages/react-devtools-shared/src/devtools/views/hooks.js index f027f751d399f..57ebb69f6e01c 100644 --- a/packages/react-devtools-shared/src/devtools/views/hooks.js +++ b/packages/react-devtools-shared/src/devtools/views/hooks.js @@ -8,13 +8,7 @@ */ import throttle from 'lodash.throttle'; -import { - useCallback, - useEffect, - useLayoutEffect, - useMemo, - useState, -} from 'react'; +import {useCallback, useEffect, useLayoutEffect, useState} from 'react'; import {unstable_batchedUpdates as batchedUpdates} from 'react-dom'; import { localStorageGetItem, @@ -42,11 +36,14 @@ export function useEditableValue( const [parsedValue, setParsedValue] = useState(initialValue); const [isValid, setIsValid] = useState(initialIsValid); - const reset = useCallback(() => { - setEditableValue(smartStringify(initialValue)); - setParsedValue(initialValue); - setIsValid(initialIsValid); - }, []); + const reset = useCallback( + () => { + setEditableValue(smartStringify(initialValue)); + setParsedValue(initialValue); + setIsValid(initialIsValid); + }, + [initialValue, initialIsValid], + ); const update = useCallback(newValue => { let isNewValueValid = false; @@ -65,17 +62,14 @@ export function useEditableValue( }); }, []); - return useMemo( - () => ({ - editableValue, - hasPendingChanges: smartStringify(initialValue) !== editableValue, - isValid, - parsedValue, - reset, - update, - }), - [editableValue, initialValue, isValid, parsedValue], - ); + return { + editableValue, + hasPendingChanges: smartStringify(initialValue) !== editableValue, + isValid, + parsedValue, + reset, + update, + }; } export function useIsOverflowing(