Skip to content

Commit

Permalink
Merge pull request Expensify#23919 from rezkiy37/fix/23818-polish-roo…
Browse files Browse the repository at this point in the history
…ms-clear-states

Fix/23818 - Polish admins-only policy room - Clear "Form's" states correctly
  • Loading branch information
amyevans authored Aug 2, 2023
2 parents 6509b07 + 0e8dba3 commit 6a38341
Showing 1 changed file with 23 additions and 18 deletions.
41 changes: 23 additions & 18 deletions src/components/Form.js
Original file line number Diff line number Diff line change
Expand Up @@ -346,24 +346,6 @@ function Form(props) {
});
});

// We need to verify that all references and values are still actual.
// We should not store it when e.g. some input has been unmounted
_.each(inputRefs.current, (inputRef, inputID) => {
if (inputRef) {
return;
}

delete inputRefs.current[inputID];

setInputValues((prevState) => {
const copyPrevState = _.clone(prevState);

delete copyPrevState[inputID];

return copyPrevState;
});
});

return childrenElements;
},
[errors, inputRefs, inputValues, onValidate, props.draftValues, props.formID, props.formState, setTouchedInput],
Expand Down Expand Up @@ -435,6 +417,29 @@ function Form(props) {
],
);

useEffect(() => {
_.each(inputRefs.current, (inputRef, inputID) => {
if (inputRef) {
return;
}

delete inputRefs.current[inputID];
delete touchedInputs.current[inputID];
delete lastValidatedValues.current[inputID];

setInputValues((prevState) => {
const copyPrevState = _.clone(prevState);

delete copyPrevState[inputID];

return copyPrevState;
});
});
// We need to verify that all references and values are still actual.
// We should not store it when e.g. some input has been unmounted.
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [children]);

return (
<SafeAreaConsumer>
{({safeAreaPaddingBottomStyle}) =>
Expand Down

0 comments on commit 6a38341

Please sign in to comment.