mirror of
https://github.com/hanzoai/react.git
synced 2026-09-24 17:02:27 +00:00
Replaced === check with Object.is() to support values like NaN (#16934)
This commit is contained in:
@@ -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;
|
||||
|
||||
|
||||
@@ -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',
|
||||
|
||||
Reference in New Issue
Block a user