Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issues with some type of Map keys #34

Closed
arthurdenner opened this issue Dec 2, 2019 · 1 comment · Fixed by #35
Closed

Issues with some type of Map keys #34

arthurdenner opened this issue Dec 2, 2019 · 1 comment · Fixed by #35

Comments

@arthurdenner
Copy link
Contributor

Hi! 👋

Problem

We added support for Map a while ago, but there are some issues with it when you set a key to be an object or a function.

When it's a function, it renders empty and we get a warning from React about children being of type function. When it's an object, it breaks because children can't be an object.

Demo

https://codesandbox.io/s/staging-worker-wrhqp

Solution

I'm not sure about what the expected output should be in this case, but if you want to, we can add a method to stringify object and functions, like:

getCustomName(name: any) {
  if (typeof name === 'object') {
    let customName: string

    try {
      customName = JSON.stringify(name)
    } catch (e) {
      customName = String(name)
    }

    return customName
  }

  if (typeof name === 'function') {
    return '' + name
  }

  return name
}

The output to the failing logs on the demo would be:

image

@samdenty
Copy link
Owner

samdenty commented Dec 2, 2019

proposed solution looks good, prs open

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants