Open
Description
Bug report
Current Behavior
Value of meta.initialValue
is null in case if path is path.to.property
for object
{
"path": {
"to": null
}
}
const [_, meta] = useField("path.to.property")
meta.initialValue === null
Expected behavior
Value of meta.initialValue
is undefined
const [_, meta] = useField("path.to.property")
meta.initialValue === undefined
Suggested solution(s)
export function getIn(
obj: any,
key: string | string[],
def?: any,
p: number = 0
) {
const path = toPath(key);
while (obj && p < path.length) {
obj = obj[path[p++]];
}
// check if path is not in the end
if(p !== path.length && obj === null)
return undefined
return obj === undefined ? def : obj;
}
Your environment
Software | Version(s) |
---|---|
Formik | 2.2.5 |
React | 16.14.0 |
Operating System | linux |