Controls Need Functional Component, PropTypes, and DefaultProps? #14133
Replies: 3 comments 8 replies
-
Hi, @KenACollins I've picked up on this discussion and I wanted to give some insights into what was mentioned.
This is accurate and you can use class-based components at will. See here for an example component and story. Also you can check a deployed version of said component here.
That's true and you need to include type checking with Let me know if you have further questions and we'll go from there. Stay safe |
Beta Was this translation helpful? Give feedback.
-
Okay, getting back to the issues I cited above, Storybook treats functional components differently from class components when it comes to the Controls panel. This is true of Storybook essentials package at 6.1.21 as well as 6.2.0-BETA. I currently have 6.2.0-BETA as that is the only way to get PR# 13898 and be able to exclude properties I don't want. I started with our Button class component. I pulled out the static propTypes and defaultProps blocks and placed them outside the component definition at the bottom of the file. I then made a copy of this revised class component and rewrote it as a function. For functional components, it works great. See screen shot below. But the experience is different for class-based components. The Controls panel is sparse, devoid of properties, except those I explicitly code in the args property of the story and it leaves out the helpful comments and default values that the class component contains. Result is below. Now, if I had to explicitly code every property I wanted to see via the args property, that would be okay, but the issue I can't solve is the missing comments. I need them to explain the meaning behind each property. We have a lot of reusable class-based components. Am I forced to rewrite them all as functions with React Hooks? |
Beta Was this translation helpful? Give feedback.
-
@shilman, @jonniebigodes - While my focus in this discussion topic is on the table that appears on the Controls panel, I found the |
Beta Was this translation helpful? Give feedback.
-
The documentation for controls is inaccurate and incomplete.
Inaccurate: The docs include this statement "Controls does not require any modification to your components." but I found this not to be true. I had to change a class-based component to a functional component in order to see all my properties show up with their comments.
Incomplete: The docs don't explain at all how to get a comment to appear above each control on the Controls and Docs tabs. By reverse engineering the examples that come with a vanilla install I was able to figure out that I need MyComponent.propTypes and MyComponent.defaultProps in MyComponent.js, and each property requires a preceding comment.
Beta Was this translation helpful? Give feedback.
All reactions