fix: ensures arrays and blocks reset row count on initialState change

This commit is contained in:
James
2021-04-02 08:48:12 -04:00
parent 27cebccd4a
commit 9a7c0e3dbd
2 changed files with 9 additions and 6 deletions

View File

@@ -39,7 +39,9 @@ const ArrayFieldType: React.FC<Props> = (props) => {
} = props;
const [rows, dispatchRows] = useReducer(reducer, []);
const { getDataByPath, dispatchFields } = useForm();
const formContext = useForm();
const { dispatchFields } = formContext;
const path = pathFromProps || name;
@@ -87,9 +89,9 @@ const ArrayFieldType: React.FC<Props> = (props) => {
}, [moveRow]);
useEffect(() => {
const data = getDataByPath(path);
const data = formContext.getDataByPath(path);
dispatchRows({ type: 'SET_ALL', data: data || [] });
}, [getDataByPath, path]);
}, [formContext, path]);
useEffect(() => {
setValue(rows?.length || 0);

View File

@@ -47,7 +47,8 @@ const Blocks: React.FC<Props> = (props) => {
const path = pathFromProps || name;
const [rows, dispatchRows] = useReducer(reducer, []);
const { getDataByPath, dispatchFields } = useForm();
const formContext = useForm();
const { dispatchFields } = formContext;
const memoizedValidate = useCallback((value) => {
const validationResult = validate(
@@ -106,9 +107,9 @@ const Blocks: React.FC<Props> = (props) => {
}, [moveRow]);
useEffect(() => {
const data = getDataByPath(path);
const data = formContext.getDataByPath(path);
dispatchRows({ type: 'SET_ALL', data: data || [] });
}, [getDataByPath, path]);
}, [formContext, path]);
useEffect(() => {
setValue(rows?.length || 0);