fix: allow parent updates to the TextField component
By setting an effect on the `value` prop, changes can be detected and the state can be updated. ref: N25B-287
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import {useState} from "react";
|
import {useEffect, useState} from "react";
|
||||||
import styles from "./TextField.module.css";
|
import styles from "./TextField.module.css";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -86,6 +86,11 @@ export function TextField({
|
|||||||
}) {
|
}) {
|
||||||
const [inputValue, setInputValue] = useState(value);
|
const [inputValue, setInputValue] = useState(value);
|
||||||
|
|
||||||
|
// The value may be changed from the outside, for example, when a program is loaded. We need to update the input value accordingly.
|
||||||
|
useEffect(() => {
|
||||||
|
setInputValue(value);
|
||||||
|
}, [value]);
|
||||||
|
|
||||||
const onCommit = () => setValue(inputValue);
|
const onCommit = () => setValue(inputValue);
|
||||||
|
|
||||||
return <RealtimeTextField
|
return <RealtimeTextField
|
||||||
|
|||||||
Reference in New Issue
Block a user