Replaced === check with Object.is() to support values like NaN (#16934)

This commit is contained in:
Brian Vaughn
2019-09-27 16:54:53 -07:00
committed by GitHub
parent 6db52bfb76
commit 7033ff7c77
2 changed files with 19 additions and 2 deletions
@@ -23,6 +23,24 @@ describe('useEditableValue', () => {
useEditableValue = require('../devtools/views/hooks').useEditableValue;
});
it('should not cause a loop with values like NaN', () => {
let state;
function Example({value = NaN}) {
const tuple = useEditableValue(value);
state = tuple[0];
return null;
}
const container = document.createElement('div');
ReactDOM.render(<Example />, container);
expect(state.editableValue).toEqual('NaN');
expect(state.externalValue).toEqual(NaN);
expect(state.parsedValue).toEqual(NaN);
expect(state.hasPendingChanges).toBe(false);
expect(state.isValid).toBe(true);
});
it('should override editable state when external props are updated', () => {
let state;
+1 -2
View File
@@ -87,8 +87,7 @@ export function useEditableValue(
isValid: true,
parsedValue: externalValue,
});
if (state.externalValue !== externalValue) {
if (!Object.is(state.externalValue, externalValue)) {
if (!state.hasPendingChanges) {
dispatch({
type: 'RESET',