Fix formatting

This commit is contained in:
Ola Hungerford
2025-03-04 20:55:57 -07:00
parent dd02b69036
commit 00836dbf9e

View File

@@ -55,23 +55,26 @@ const DynamicJsonForm = ({
const timeoutRef = useRef<ReturnType<typeof setTimeout>>(); const timeoutRef = useRef<ReturnType<typeof setTimeout>>();
// Create a debounced function to update parent state // Create a debounced function to update parent state
const debouncedUpdateParent = useCallback((jsonString: string) => { const debouncedUpdateParent = useCallback(
// Clear any existing timeout (jsonString: string) => {
if (timeoutRef.current) { // Clear any existing timeout
clearTimeout(timeoutRef.current); if (timeoutRef.current) {
} clearTimeout(timeoutRef.current);
// Set a new timeout
timeoutRef.current = setTimeout(() => {
try {
const parsed = JSON.parse(jsonString);
onChange(parsed);
setJsonError(undefined);
} catch {
// Don't set error during normal typing
} }
}, 300);
}, [onChange, setJsonError]); // Set a new timeout
timeoutRef.current = setTimeout(() => {
try {
const parsed = JSON.parse(jsonString);
onChange(parsed);
setJsonError(undefined);
} catch {
// Don't set error during normal typing
}
}, 300);
},
[onChange, setJsonError],
);
// Update rawJsonValue when value prop changes // Update rawJsonValue when value prop changes
useEffect(() => { useEffect(() => {
@@ -353,7 +356,7 @@ const DynamicJsonForm = ({
onChange={(newValue) => { onChange={(newValue) => {
// Always update local state // Always update local state
setRawJsonValue(newValue); setRawJsonValue(newValue);
// Use the debounced function to attempt parsing and updating parent // Use the debounced function to attempt parsing and updating parent
debouncedUpdateParent(newValue); debouncedUpdateParent(newValue);
}} }}