Skip to content

Commit

Permalink
Add support for defaultValue for field inside field array + update dts
Browse files Browse the repository at this point in the history
  • Loading branch information
nikhilag committed Nov 3, 2021
1 parent 8e78fa6 commit ddfd0f2
Show file tree
Hide file tree
Showing 3 changed files with 593 additions and 581 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,14 @@
"@types/react": "^17.0.11",
"@types/react-dom": "^17.0.8",
"babel-jest": "^27.2.4",
"dts-cli": "0.17.1",
"dts-cli": "0.19.4",
"husky": "^4.3.0",
"react": "^17.0.1",
"react-dom": "^17.0.1",
"recoil": "0.4.1",
"size-limit": "^5.0.5",
"tslib": "^2.3.1",
"typescript": "4.4.3"
"typescript": "4.4.4"
},
"dependencies": {
"core-js": "^3.18.1"
Expand Down
8 changes: 8 additions & 0 deletions src/FormProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,14 @@ export function useField<D = any, E = any>(props: IFieldProps<D>) {
validate,
} as Partial<IFieldAtomValue>)
);
} else if (atomValue.initVer === initialValues.version && defaultValue) {
// Useful for setting field value as default value inside field array
setAtomValue((val) => {
if (!val.data) {
return Object.assign({}, val, { data: defaultValue });
}
return val;
});
}
}, [initializeFieldValue, initialValues.version, atomValue.initVer]);

Expand Down
Loading

0 comments on commit ddfd0f2

Please sign in to comment.