Skip to content

Commit b0912d4

Browse files
committed
feat: Added initial values
1 parent 4d94642 commit b0912d4

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

src/Form.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,11 @@ export const Form: React.FC<FormProps> = props => {
3232
useEffect(() => {
3333
// Set initial values
3434
if (!isControlled) {
35-
setValue(Array.from({ length: sections.length }, () => ({})));
35+
props.form.sections.forEach((section, index) => {
36+
setValueAndPropagate(index, section.fields
37+
.map(field => (field.initialValue !== undefined ? { [field.name]: field.initialValue } : {}))
38+
.reduce((obj1, obj2) => ({ ...obj1, ...obj2 }), {}));
39+
})
3640

3741

3842
// setValueAndPropagate({

0 commit comments

Comments
 (0)