fixes bug with adding blocks and arrays due to async buildStateFromSchema
This commit is contained in:
@@ -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]);
|
||||
|
||||
|
||||
@@ -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]);
|
||||
|
||||
|
||||
@@ -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]);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user