8000 Unexpected value of meta.initialValue · Issue #3181 · jaredpalmer/formik · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Unexpected value of meta.initialValue #3181
Open
@tadeas22

Description

@tadeas22

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0