Skip to content

Commit c53c79a

Browse files
Prettified changes.
1 parent 20280fb commit c53c79a

File tree

3 files changed

+30
-19
lines changed

3 files changed

+30
-19
lines changed

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

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,11 @@ export default function EditableName({
2525
const [isValid, setIsValid] = useState(false);
2626
const inputRef = useRef<HTMLInputElement | null>(null);
2727

28-
useEffect(
29-
() => {
30-
if (inputRef.current !== null) {
31-
inputRef.current.focus();
32-
}
33-
},
34-
[],
35-
);
28+
useEffect(() => {
29+
if (inputRef.current !== null) {
30+
inputRef.current.focus();
31+
}
32+
}, []);
3633

3734
const handleChange = useCallback(
3835
({target}) => {
@@ -59,10 +56,10 @@ export default function EditableName({
5956
if ((eventKey === 'Enter' || eventKey === 'Tab') && isValid) {
6057
overrideNameFn(editableName);
6158
} else if (eventKey === 'Escape') {
62-
setEditableName(name);
59+
setEditableName(initialValue);
6360
}
6461
},
65-
[editableName, setEditableName, isValid, name, overrideNameFn],
62+
[editableName, setEditableName, isValid, initialValue, overrideNameFn],
6663
);
6764

6865
return (

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

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

10-
import React, {Fragment, useEffect, useCallback, useRef, useState} from 'react';
10+
import React, {Fragment, useCallback, useRef, useState} from 'react';
1111
import Button from '../Button';
1212
import ButtonIcon from '../ButtonIcon';
1313
import styles from './EditableValue.css';
@@ -22,12 +22,6 @@ type EditableValueProps = {|
2222
initialValue: any,
2323
|};
2424

25-
function useEditableValue(initialValue) {
26-
const [editableValue, setEditableValue] = useState(JSON.stringify(initialValue));
27-
28-
return [editableValue, (value, {shouldStringify} = {}) => (shouldStringify ? setEditableValue(JSON.stringify(value)) : setEditableValue(value))];
29-
}
30-
3125
export default function EditableValue({
3226
dataType,
3327
overrideValueFn,
@@ -102,7 +96,8 @@ export default function EditableValue({
10296
[editableValue, isValid, dataType, overrideValueFn, path, initialValue],
10397
);
10498

105-
let inputValue = initialValue === undefined ? '' : JSON.stringify(initialValue);
99+
let inputValue =
100+
initialValue === undefined ? '' : JSON.stringify(initialValue);
106101
if (hasPendingChanges) {
107102
inputValue = editableValue;
108103
}
@@ -151,3 +146,22 @@ export default function EditableValue({
151146
</Fragment>
152147
);
153148
}
149+
150+
function useEditableValue(initialValue: any): [any, Function] {
151+
const [editableValue, setEditableValue] = useState(
152+
JSON.stringify(initialValue),
153+
);
154+
155+
function setEditableValueWithStringify(
156+
value: any,
157+
{shouldStringify}: Object = {},
158+
) {
159+
if (shouldStringify) {
160+
setEditableValue(JSON.stringify(value));
161+
}
162+
163+
setEditableValue(value);
164+
}
165+
166+
return [editableValue, setEditableValueWithStringify];
167+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {meta} from '../../../hydration';
1616
import styles from './KeyValue.css';
1717

1818
import type {InspectPath} from './SelectedElement';
19-
import EditableName from "./EditableName";
19+
import EditableName from './EditableName';
2020

2121
type OverrideValueFn = (path: Array<string | number>, value: any) => void;
2222

0 commit comments

Comments
 (0)