From 3b2e899c14e17912b20ba230dc5377227761a03c Mon Sep 17 00:00:00 2001 From: daniyal Date: Mon, 30 Sep 2024 14:52:19 +0500 Subject: [PATCH] fix: update form state on getting existing mod data --- src/components/ModForm.tsx | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/components/ModForm.tsx b/src/components/ModForm.tsx index 982fc75..8be5ba8 100644 --- a/src/components/ModForm.tsx +++ b/src/components/ModForm.tsx @@ -60,7 +60,7 @@ export const ModForm = ({ existingModData }: ModFormProps) => { const [isPublishing, setIsPublishing] = useState(false) const [gameOptions, setGameOptions] = useState([]) const [formState, setFormState] = useState( - initializeFormState(existingModData) + initializeFormState() ) const [formErrors, setFormErrors] = useState({}) @@ -70,6 +70,12 @@ export const ModForm = ({ existingModData }: ModFormProps) => { } }, [location.pathname]) // Only trigger when the pathname changes to submit-mod + useEffect(() => { + if (existingModData) { + setFormState(initializeFormState(existingModData)) + } + }, [existingModData]) + useEffect(() => { const options = games.map((game) => ({ label: game['Game Name'],