'How can i clean up such a function when not using useEffect hook?

I am using the function below with formik. It runs as expected but i noticed that when a user navigates away from the screen it's running, there's a memory leak of Can't perform a React state update on an unmounted component. How can I clean this up to clear subscriptions? Am okey using hooks. How would it look like?

const forgotPassword = async (values, formikActions) => {
  try {
    setIsLoading(true);
    const response = await client.post("/user/post-reset-email", {
      email: values.email,
      url: "https://productionServer/mobileClient-reset-password",
    });
    // console.log(response, "Res Needed");
    formikActions.setSubmitting(false);
    formikActions.resetForm();
    if (!response.ok) {
      updateNotification(setMessageError, response?.data?.message);
    } else {
      updateNotification(setMessageError, response?.data?.message, "success");
    }
    formikActions.resetForm();
    setIsLoading(false);
  } catch (error) {
    console.log(error, "Error Captured");
  }
};

UpdateNotification is an imported helper function but this is how it looks like;

export const updateNotification = (updater, text, type = "error") => {
  updater({ text, type });
  setTimeout(() => {
    updater({ text: "", type: "" });
  }, 3000);
};

Thank you!

then just call this is a Form....

<Form
            initialValues={{ email: "" }}
            onSubmit={forgetPassword}
            validationSchema={validationSchema}
          >
            <FormField
              name="email"
              autoCapitalize="none"
              autoCorrect={false}
              icon="email"
              keyboardType="email-address"
              placeholder="Enter Email..."
            />


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source