Skip to content

Commit 043b2c4

Browse files
authored
Additional changes
* Removed unused inputRef * Added explanatory inline comment
1 parent affe779 commit 043b2c4

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

packages/react-devtools-shared/src/devtools/views/Components/EditableValue.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*/
99

1010
import * as React from 'react';
11-
import {Fragment, useRef} from 'react';
11+
import {Fragment} from 'react';
1212
import styles from './EditableValue.css';
1313
import {useEditableValue} from '../hooks';
1414

@@ -27,7 +27,6 @@ export default function EditableValue({
2727
path,
2828
value,
2929
}: EditableValueProps) {
30-
const inputRef = useRef<HTMLInputElement | null>(null);
3130
const [state, dispatch] = useEditableValue(value);
3231
const {editableValue, hasPendingChanges, isValid, parsedValue} = state;
3332

@@ -50,6 +49,12 @@ export default function EditableValue({
5049
editableValue: target.checked,
5150
externalValue: value,
5251
});
52+
53+
// Unlike <input type="text"> which has both an onChange and an onBlur,
54+
// <input type="checkbox"> updates state *and* applies changes in a single event.
55+
// So we read from target.checked rather than parsedValue (which has not yet updated).
56+
// We also don't check isValid (because that hasn't changed yet either);
57+
// we don't need to check it anyway, since target.checked is always a boolean.
5358
overrideValueFn(path, target.checked);
5459
};
5560

@@ -93,7 +98,6 @@ export default function EditableValue({
9398
onChange={handleChange}
9499
onKeyDown={handleKeyDown}
95100
placeholder={placeholder}
96-
ref={inputRef}
97101
type="text"
98102
value={editableValue}
99103
/>

0 commit comments

Comments
 (0)