From c4e5e09434b08e6e496c1f93ae87e7a92cf2f42d Mon Sep 17 00:00:00 2001 From: Kazuki Murahama Date: Fri, 16 Oct 2020 07:12:04 +0900 Subject: [PATCH] fixed no fields bug --- src/js/config/FormFieldSelectTable.tsx | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/js/config/FormFieldSelectTable.tsx b/src/js/config/FormFieldSelectTable.tsx index 5bef2e7..663b7f0 100644 --- a/src/js/config/FormFieldSelectTable.tsx +++ b/src/js/config/FormFieldSelectTable.tsx @@ -56,6 +56,12 @@ const useFormFieldSelectTable = ( ) => { const [appFields, setAppfields] = useState([]); const [selectedFields, setSelectedFields] = useState(defaultSelectedFields); + useEffect(() => { + // reset initial value when no default selected fields + if (defaultSelectedFields.length === 0 && appFields.length > 0) { + setSelectedFields([{ code: appFields[0].code }]); + } + }, [appFields, defaultSelectedFields.length]); const onChangeSelect = useCallback( (event: SyntheticEvent, index: number) => { const value = event.currentTarget.value;