Skip to content

Commit 6a38341

Browse files
authored
Merge pull request #23919 from rezkiy37/fix/23818-polish-rooms-clear-states
Fix/23818 - Polish admins-only policy room - Clear "Form's" states correctly
2 parents 6509b07 + 0e8dba3 commit 6a38341

File tree

1 file changed

+23
-18
lines changed

1 file changed

+23
-18
lines changed

src/components/Form.js

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -346,24 +346,6 @@ function Form(props) {
346346
});
347347
});
348348

349-
// We need to verify that all references and values are still actual.
350-
// We should not store it when e.g. some input has been unmounted
351-
_.each(inputRefs.current, (inputRef, inputID) => {
352-
if (inputRef) {
353-
return;
354-
}
355-
356-
delete inputRefs.current[inputID];
357-
358-
setInputValues((prevState) => {
359-
const copyPrevState = _.clone(prevState);
360-
361-
delete copyPrevState[inputID];
362-
363-
return copyPrevState;
364-
});
365-
});
366-
367349
return childrenElements;
368350
},
369351
[errors, inputRefs, inputValues, onValidate, props.draftValues, props.formID, props.formState, setTouchedInput],
@@ -435,6 +417,29 @@ function Form(props) {
435417
],
436418
);
437419

420+
useEffect(() => {
421+
_.each(inputRefs.current, (inputRef, inputID) => {
422+
if (inputRef) {
423+
return;
424+
}
425+
426+
delete inputRefs.current[inputID];
427+
delete touchedInputs.current[inputID];
428+
delete lastValidatedValues.current[inputID];
429+
430+
setInputValues((prevState) => {
431+
const copyPrevState = _.clone(prevState);
432+
433+
delete copyPrevState[inputID];
434+
435+
return copyPrevState;
436+
});
437+
});
438+
// We need to verify that all references and values are still actual.
439+
// We should not store it when e.g. some input has been unmounted.
440+
// eslint-disable-next-line react-hooks/exhaustive-deps
441+
}, [children]);
442+
438443
return (
439444
<SafeAreaConsumer>
440445
{({safeAreaPaddingBottomStyle}) =>

0 commit comments

Comments
 (0)