Skip to content

Commit c7e03b5

Browse files
author
Brian Vaughn
committed
Fixed a reset/state bug in useEditableValue() hook and removed unnecessary useMemo()
1 parent 066b762 commit c7e03b5

File tree

1 file changed

+17
-23
lines changed
  • packages/react-devtools-shared/src/devtools/views

1 file changed

+17
-23
lines changed

packages/react-devtools-shared/src/devtools/views/hooks.js

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,7 @@
88
*/
99

1010
import throttle from 'lodash.throttle';
11-
import {
12-
useCallback,
13-
useEffect,
14-
useLayoutEffect,
15-
useMemo,
16-
useState,
17-
} from 'react';
11+
import {useCallback, useEffect, useLayoutEffect, useState} from 'react';
1812
import {unstable_batchedUpdates as batchedUpdates} from 'react-dom';
1913
import {
2014
localStorageGetItem,
@@ -42,11 +36,14 @@ export function useEditableValue(
4236
const [parsedValue, setParsedValue] = useState(initialValue);
4337
const [isValid, setIsValid] = useState(initialIsValid);
4438

45-
const reset = useCallback(() => {
46-
setEditableValue(smartStringify(initialValue));
47-
setParsedValue(initialValue);
48-
setIsValid(initialIsValid);
49-
}, []);
39+
const reset = useCallback(
40+
() => {
41+
setEditableValue(smartStringify(initialValue));
42+
setParsedValue(initialValue);
43+
setIsValid(initialIsValid);
44+
},
45+
[initialValue, initialIsValid],
46+
);
5047

5148
const update = useCallback(newValue => {
5249
let isNewValueValid = false;
@@ -65,17 +62,14 @@ export function useEditableValue(
6562
});
6663
}, []);
6764

68-
return useMemo(
69-
() => ({
70-
editableValue,
71-
hasPendingChanges: smartStringify(initialValue) !== editableValue,
72-
isValid,
73-
parsedValue,
74-
reset,
75-
update,
76-
}),
77-
[editableValue, initialValue, isValid, parsedValue],
78-
);
65+
return {
66+
editableValue,
67+
hasPendingChanges: smartStringify(initialValue) !== editableValue,
68+
isValid,
69+
parsedValue,
70+
reset,
71+
update,
72+
};
7973
}
8074

8175
export function useIsOverflowing(

0 commit comments

Comments
 (0)