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 c7e03b5
Showing 1 changed file with 17 additions and 23 deletions.
40 changes: 17 additions & 23 deletions packages/react-devtools-shared/src/devtools/views/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand All @@ -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(
Expand Down

0 comments on commit c7e03b5

Please sign in to comment.