Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/23818 - Polish admins-only policy room - Clear "Form's" states correctly #23919

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 23 additions & 18 deletions src/components/Form.js
Original file line number Diff line number Diff line change
Expand Up @@ -343,24 +343,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 @@ -432,6 +414,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
Loading