fix(auth): implement proper debounce ref for forgot password requests (#28490)
* fix(auth): implement proper debounce ref for forgot password requests * Add cleanup for debounced submit function Cancel debounced function on component unmount. --------- Co-authored-by: javidan <javababayev@gmail.com> Co-authored-by: Sahitya Chandra <sahityajb@gmail.com>
This commit is contained in:
co-authored by
javidan
Sahitya Chandra
parent
87fb2abf59
commit
15005d89bd
@@ -54,9 +54,18 @@ export default function ForgotPassword(props: PageProps) {
|
||||
}
|
||||
};
|
||||
|
||||
const debouncedHandleSubmitPasswordRequest = debounce(submitForgotPasswordRequest, 250);
|
||||
const submitRef = React.useRef(submitForgotPasswordRequest);
|
||||
submitRef.current = submitForgotPasswordRequest;
|
||||
|
||||
const handleSubmit = async (e: SyntheticEvent) => {
|
||||
const debouncedHandleSubmitPasswordRequest = React.useRef(
|
||||
debounce((args: { email: string }) => submitRef.current(args), 250)
|
||||
).current;
|
||||
|
||||
React.useEffect(() => {
|
||||
return () => debouncedHandleSubmitPasswordRequest.cancel();
|
||||
}, []);
|
||||
|
||||
const handleSubmit = (e: SyntheticEvent) => {
|
||||
e.preventDefault();
|
||||
|
||||
if (!email) {
|
||||
@@ -71,7 +80,7 @@ export default function ForgotPassword(props: PageProps) {
|
||||
setError(null);
|
||||
setSuccess(false);
|
||||
|
||||
await debouncedHandleSubmitPasswordRequest({ email });
|
||||
debouncedHandleSubmitPasswordRequest({ email });
|
||||
};
|
||||
|
||||
const Success = () => {
|
||||
|
||||
Reference in New Issue
Block a user