Skip to content

Commit 1a0f6ad

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

File tree

1 file changed

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

1 file changed

+16
-17
lines changed

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

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import {
1212
useCallback,
1313
useEffect,
1414
useLayoutEffect,
15-
useMemo,
1615
useState,
1716
} from 'react';
1817
import {unstable_batchedUpdates as batchedUpdates} from 'react-dom';
@@ -42,11 +41,14 @@ export function useEditableValue(
4241
const [parsedValue, setParsedValue] = useState(initialValue);
4342
const [isValid, setIsValid] = useState(initialIsValid);
4443

45-
const reset = useCallback(() => {
46-
setEditableValue(smartStringify(initialValue));
47-
setParsedValue(initialValue);
48-
setIsValid(initialIsValid);
49-
}, []);
44+
const reset = useCallback(
45+
() => {
46+
setEditableValue(smartStringify(initialValue));
47+
setParsedValue(initialValue);
48+
setIsValid(initialIsValid);
49+
},
50+
[initialValue, initialIsValid],
51+
);
5052

5153
const update = useCallback(newValue => {
5254
let isNewValueValid = false;
@@ -65,17 +67,14 @@ export function useEditableValue(
6567
});
6668
}, []);
6769

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-
);
70+
return {
71+
editableValue,
72+
hasPendingChanges: smartStringify(initialValue) !== editableValue,
73+
isValid,
74+
parsedValue,
75+
reset,
76+
update,
77+
};
7978
}
8079

8180
export function useIsOverflowing(

0 commit comments

Comments
 (0)