fix: persist value in ControlledCustomAutocomplete when it depends on other fields
This commit is contained in:
@@ -61,6 +61,7 @@ function ControlledCustomAutocomplete(props) {
|
|||||||
const [isSingleChoice, setSingleChoice] = React.useState(undefined);
|
const [isSingleChoice, setSingleChoice] = React.useState(undefined);
|
||||||
const priorStepsWithExecutions = React.useContext(StepExecutionsContext);
|
const priorStepsWithExecutions = React.useContext(StepExecutionsContext);
|
||||||
const editorRef = React.useRef(null);
|
const editorRef = React.useRef(null);
|
||||||
|
const mountedRef = React.useRef(false);
|
||||||
|
|
||||||
const renderElement = React.useCallback(
|
const renderElement = React.useCallback(
|
||||||
(props) => <Element {...props} disabled={disabled} />,
|
(props) => <Element {...props} disabled={disabled} />,
|
||||||
@@ -94,11 +95,15 @@ function ControlledCustomAutocomplete(props) {
|
|||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
|
if (mountedRef.current) {
|
||||||
const hasDependencies = dependsOnValues.length;
|
const hasDependencies = dependsOnValues.length;
|
||||||
if (hasDependencies) {
|
if (hasDependencies) {
|
||||||
// Reset the field when a dependent has been updated
|
// Reset the field when a dependent has been updated
|
||||||
resetEditor(editor);
|
resetEditor(editor);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
mountedRef.current = true;
|
||||||
|
}
|
||||||
}, dependsOnValues);
|
}, dependsOnValues);
|
||||||
|
|
||||||
React.useEffect(
|
React.useEffect(
|
||||||
|
Reference in New Issue
Block a user