fixes bug with adding blocks and arrays due to async buildStateFromSchema

This commit is contained in:
James
2020-10-08 23:03:22 -04:00
parent ffc3f10177
commit f880072697
3 changed files with 4 additions and 2 deletions

View File

@@ -316,6 +316,7 @@ const Form = (props) => {
}, 15000, [fields]);
useEffect(() => {
contextRef.current = { ...contextRef.current }; // triggers rerender of all components that subscribe to form
setModified(false);
}, [locale]);

View File

@@ -62,9 +62,9 @@ const ArrayFieldType = (props) => {
});
const addRow = useCallback(async (rowIndex) => {
dispatchRows({ type: 'ADD', rowIndex });
const subFieldState = await buildStateFromSchema(fields);
dispatchFields({ type: 'ADD_ROW', rowIndex, subFieldState, path });
dispatchRows({ type: 'ADD', rowIndex });
setValue(value + 1);
}, [dispatchRows, dispatchFields, fields, path, setValue, value]);

View File

@@ -73,9 +73,10 @@ const Blocks = (props) => {
const addRow = useCallback(async (rowIndex, blockType) => {
const block = blocks.find((potentialBlock) => potentialBlock.slug === blockType);
dispatchRows({ type: 'ADD', rowIndex, blockType });
const subFieldState = await buildStateFromSchema(block.fields);
dispatchFields({ type: 'ADD_ROW', rowIndex, subFieldState, path, blockType });
dispatchRows({ type: 'ADD', rowIndex, blockType });
setValue(value + 1);
}, [path, setValue, value, blocks, dispatchFields]);