From bcef516d1a430c44d8b50a92c146a17fb3ffd5a8 Mon Sep 17 00:00:00 2001 From: amitbadala Date: Fri, 27 Oct 2023 19:32:41 +0530 Subject: [PATCH] Remove useEffect --- lib/build/emailpassword-shared7.js | 52 +++++++++---------- .../components/library/formBase.tsx | 52 +++++++++---------- 2 files changed, 51 insertions(+), 53 deletions(-) diff --git a/lib/build/emailpassword-shared7.js b/lib/build/emailpassword-shared7.js index aec97b722..a2672b8b5 100644 --- a/lib/build/emailpassword-shared7.js +++ b/lib/build/emailpassword-shared7.js @@ -436,24 +436,24 @@ function Label(_a) { ); } -var fetchDefaultValue = function (field) { - if (field && field.getDefaultValue) { - try { - if (typeof field.getDefaultValue !== "function") { - throw new Error("getDefaultValue for ".concat(field.id, " must be a function")); - } - var defaultValue = field.getDefaultValue(); - if (typeof defaultValue !== "string") { - throw new Error("getDefaultValue for ".concat(field.id, " must return a string")); - } else { - return defaultValue; - } - } catch (error) { - console.error(error); - } - } - return ""; -}; +// const fetchDefaultValue = (field: FormFieldThemeProps): string => { +// if (field && field.getDefaultValue) { +// try { +// if (typeof field.getDefaultValue !== "function") { +// throw new Error(`getDefaultValue for ${field.id} must be a function`); +// } +// const defaultValue = field.getDefaultValue(); +// if (typeof defaultValue !== "string") { +// throw new Error(`getDefaultValue for ${field.id} must return a string`); +// } else { +// return defaultValue; +// } +// } catch (error) { +// console.error(error); +// } +// } +// return ""; +// }; var FormBase = function (props) { var footer = props.footer, buttonLabel = props.buttonLabel, @@ -481,15 +481,13 @@ var FormBase = function (props) { var _b = React.useState(false), isLoading = _b[0], setIsLoading = _b[1]; - React.useEffect(function () { - var initialValues = props.formFields.map(function (f) { - return { - id: f.id, - value: fetchDefaultValue(f), - }; - }); - setFieldStates(initialValues); - }, []); + // useEffect(() => { + // const initialValues = props.formFields.map((f) => ({ + // id: f.id, + // value: fetchDefaultValue(f), + // })); + // setFieldStates(initialValues); + // }, []); var updateFieldState = React.useCallback( function (id, update) { setFieldStates(function (os) { diff --git a/lib/ts/recipe/emailpassword/components/library/formBase.tsx b/lib/ts/recipe/emailpassword/components/library/formBase.tsx index 7ea1d2510..56977fa7b 100644 --- a/lib/ts/recipe/emailpassword/components/library/formBase.tsx +++ b/lib/ts/recipe/emailpassword/components/library/formBase.tsx @@ -25,7 +25,7 @@ import STGeneralError from "supertokens-web-js/utils/error"; import { MANDATORY_FORM_FIELDS_ID_ARRAY } from "../../constants"; import type { APIFormField } from "../../../../types"; -import type { FormBaseProps, FormFieldThemeProps } from "../../types"; +import type { FormBaseProps } from "../../types"; import type { FormEvent } from "react"; import { Button, FormRow, Input, InputError, Label } from "."; @@ -37,24 +37,24 @@ type FieldState = { value: string; }; -const fetchDefaultValue = (field: FormFieldThemeProps): string => { - if (field && field.getDefaultValue) { - try { - if (typeof field.getDefaultValue !== "function") { - throw new Error(`getDefaultValue for ${field.id} must be a function`); - } - const defaultValue = field.getDefaultValue(); - if (typeof defaultValue !== "string") { - throw new Error(`getDefaultValue for ${field.id} must return a string`); - } else { - return defaultValue; - } - } catch (error) { - console.error(error); - } - } - return ""; -}; +// const fetchDefaultValue = (field: FormFieldThemeProps): string => { +// if (field && field.getDefaultValue) { +// try { +// if (typeof field.getDefaultValue !== "function") { +// throw new Error(`getDefaultValue for ${field.id} must be a function`); +// } +// const defaultValue = field.getDefaultValue(); +// if (typeof defaultValue !== "string") { +// throw new Error(`getDefaultValue for ${field.id} must return a string`); +// } else { +// return defaultValue; +// } +// } catch (error) { +// console.error(error); +// } +// } +// return ""; +// }; export const FormBase: React.FC> = (props) => { const { footer, buttonLabel, showLabels, validateOnBlur, formFields } = props; @@ -73,13 +73,13 @@ export const FormBase: React.FC> = (props) => { ); const [isLoading, setIsLoading] = useState(false); - useEffect(() => { - const initialValues = props.formFields.map((f) => ({ - id: f.id, - value: fetchDefaultValue(f), - })); - setFieldStates(initialValues); - }, []); + // useEffect(() => { + // const initialValues = props.formFields.map((f) => ({ + // id: f.id, + // value: fetchDefaultValue(f), + // })); + // setFieldStates(initialValues); + // }, []); const updateFieldState = useCallback( (id: string, update: (os: FieldState) => FieldState) => {