Skip to content

Commit

Permalink
fix(form): formRef.current change will update formitem list
Browse files Browse the repository at this point in the history
close #7250
  • Loading branch information
chenshuai2144 committed Jun 24, 2023
1 parent a550039 commit 5e977db
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions packages/form/src/components/SchemaForm/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ function BetaSchemaForm<T, ValueType = 'text'>(
const formInstance = Form.useFormInstance();

const [, forceUpdate] = useState<[]>([]);
const [formDomsDeps, updatedFormDoms] = useState<[]>([]);
const [formDomsDeps, updatedFormDoms] = useState<[]>(() => []);

const formRef = useReactiveRef<ProFormInstance | undefined>(
props.form || formInstance || form,
Expand Down Expand Up @@ -166,7 +166,7 @@ function BetaSchemaForm<T, ValueType = 'text'>(
return Boolean(field);
});
},
[action, formRef, type],
[action, !!formRef.current, type],
);

const onValuesChange: FormProps<T>['onValuesChange'] = useCallback(
Expand All @@ -184,14 +184,13 @@ function BetaSchemaForm<T, ValueType = 'text'>(
},
[propsRef, shouldUpdate],
);

const formChildrenDoms = useMemo(() => {
if (!formRef.current) return;
// like StepsForm's columns but not only for StepsForm
if (columns.length && Array.isArray(columns[0])) return;
return genItems(columns as ProFormColumnsType<T, ValueType>[]);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [columns, genItems, formDomsDeps]);
}, [columns, genItems, formDomsDeps, !!formRef.current]);

/**
* Append layoutType component specific props
Expand All @@ -207,9 +206,13 @@ function BetaSchemaForm<T, ValueType = 'text'>(
return {};
}, [columns, layoutType]);

useImperativeHandle(propsFormRef, () => {
return formRef.current;
});
useImperativeHandle(
propsFormRef,
() => {
return formRef.current;
},
[formRef.current],
);

return (
<FormRenderComponents
Expand Down

0 comments on commit 5e977db

Please sign in to comment.