question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Controls - type array of objects displayed wrongly

See original GitHub issue

Describe the bug If use argTypes control type array for array of object, in the UI it will display [object Object] instead of proper value, because it tries to “serialize array into a comma-separated string inside a textbox” .

To Reproduce Steps to reproduce the behavior:

  1. Set the argTypes of the component doc
argTypes: {
  breadcrumbs: {
    control: "array",
    table: {
      category: "Props",
    },
  },
},
  1. Set the args of the specific story to array of object
Template.args = {
  breadcrumbs: [
    { text: "Home", link: "#" },
    { text: "Category", link: "#" },
    { text: "Pants", link: "#" },
  ],
};
  1. Go to Storybook page of that component, it prints [object Object],[object Object],[object Object]

Expected behavior It should display { text: "Home", link: "#" }, { text: "Category", link: "#" }, { text: "Pants", link: "#" }

Screenshots Screen Shot 2020-12-22 at 14 57 19

System Environment Info:

System: OS: macOS 10.15.7 CPU: (12) x64 Intel® Core™ i7-8850H CPU @ 2.60GHz Binaries: Node: 14.13.0 - /usr/local/bin/node Yarn: 1.22.5 - /usr/local/bin/yarn npm: 6.14.8 - /usr/local/bin/npm Browsers: Chrome: 87.0.4280.88 Firefox: 76.0.1 Safari: 14.0

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:5
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
ghengeveldcommented, Mar 18, 2021

I really like the console.table suggestion. Like Chrome, it should automatically infer the right columns (based on all the rows rather than the first, so partial objects just have empty cells). I’ve opened a feature request for that: #14266

As of Storybook 6.2, arrays are inferred to use the object control type, which renders the JSON editor, regardless of whether the values are primitive or not.

2reactions
hydrosquallcommented, Dec 27, 2020

If all the objects in the array have the same keys, it could make sense to have a “table” display type (like the chrome console.table instead of using a JSON tree. We could have the option of either trying to infer the keys by default using the first object in the array, or letting the user pass in an explicit list of properties to use in the table.

Read more comments on GitHub >

github_iconTop Results From Across the Web

mapping an object array incorrectly in React? - Stack Overflow
My goal is to display all 4 buttons(terms), and only show the definition for that term. As it is now it keeps showing...
Read more >
Understanding the "Objects are not valid as a react child" Error ...
Lists, tables, cards, buttons, and other types of components are very often applied through the usage of the .map() array method.
Read more >
Get a Unique List of Objects in an Array of Object in JavaScript
To the tutorial! : https://yagisanatode.com/2021/07/03/get-a-unique-list-of- objects -in-an- array-of-object -in-javascript/00:00 Intro00:38 ...
Read more >
JavaScript typed arrays - MDN Web Docs
JavaScript typed arrays are array-like objects that provide a mechanism for reading and writing raw binary data in memory buffers.
Read more >
Create a custom action to generate an array of objects from a ...
Our feedback system is currently not working as expected. As a workaround, you can email docfeedback@servicenow.com. Thank you for your patience while we ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found