Skip to content

Commit

Permalink
Remove useEffect
Browse files Browse the repository at this point in the history
  • Loading branch information
amitbadala committed Oct 27, 2023
1 parent 7e6a3ec commit bcef516
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 53 deletions.
52 changes: 25 additions & 27 deletions lib/build/emailpassword-shared7.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

52 changes: 26 additions & 26 deletions lib/ts/recipe/emailpassword/components/library/formBase.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 ".";
Expand All @@ -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<FormBaseProps<any>> = (props) => {
const { footer, buttonLabel, showLabels, validateOnBlur, formFields } = props;
Expand All @@ -73,13 +73,13 @@ export const FormBase: React.FC<FormBaseProps<any>> = (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) => {
Expand Down

0 comments on commit bcef516

Please sign in to comment.