Skip to content

Commit

Permalink
Fixed a reset/state bug in useEditableValue() hook and removed unnece…
Browse files Browse the repository at this point in the history
…ssary useMemo()
  • Loading branch information
Brian Vaughn committed Sep 23, 2019
1 parent 066b762 commit 1a0f6ad
Showing 1 changed file with 16 additions and 17 deletions.
33 changes: 16 additions & 17 deletions packages/react-devtools-shared/src/devtools/views/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
useCallback,
useEffect,
useLayoutEffect,
useMemo,
useState,
} from 'react';
import {unstable_batchedUpdates as batchedUpdates} from 'react-dom';
Expand Down Expand Up @@ -42,11 +41,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;
Expand All @@ -65,17 +67,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(
Expand Down

0 comments on commit 1a0f6ad

Please sign in to comment.