Check mounted
state before using setState in onSubmit
#1152
Labels
Projects
Milestone
mounted
state before using setState in onSubmit
#1152
uniforms/packages/uniforms/src/BaseForm.tsx
Lines 261 to 278 in a103efd
In BaseForm's onSubmit method, there may be instances where calling
props.onSubmit
would cause the component to be unmounted (e.g. if an API call is successful, navigate to a different page; On failure, error boundary catches it and shows an error page). In this scenario, aWarning: Can't perform a React state update on an unmounted component. This is a no-op, but it indicates a memory leak in your application.
error would be thrown when thesetState
is called.A quick fix to this issue would be to check
this.mounted
before callingsetState
. Another fix would be to bring back theonSubmitSuccess
andonSubmitFailure
props to be called after all setStates and instruct the consumer to put their logic in here that would result in the form component being unmountedThe text was updated successfully, but these errors were encountered: