Props that differ from their defaults not rendered when showDefaultProps option is false
See original GitHub issueFirst, thanks for creating such a great utility! Now, onto the issue I’ve run into:
Taking a component used in the tests:
class DefaultPropsComponent extends React.Component {}
DefaultPropsComponent.defaultProps = {test: 'test'};
The following case correctly omits the prop from the JSX string:
reactElementToJSXString(<DefaultPropsComponent />, {showDefaultProps: false})
// <DefaultPropsComponent />
But if you change the prop’s value from the default, it doesn’t get rendered:
reactElementToJSXString(<DefaultPropsComponent test="foo" />, {showDefaultProps: false})
// <DefaultPropsComponent />
I would expect the result to be
// <DefaultPropsComponent test="foo" />
I’m just about to submit a pull request with a test and a fix.
Issue Analytics
- State:
- Created 7 years ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
Storybook templates do not handle default prop values ...
Debugging it, i discovered that using the template, the props is being initialized with "Option.none()" instead of the actual evaluated Option.
Read more >react-element-to-jsx-string - npm.io
If true, default props shown. If false, default props are omitted unless they differ from from the default value. options.showFunctions: boolean, default false....
Read more >react-element-to-jsx-string | Yarn - Package Manager
Turn a ReactElement into the corresponding JSX string. Useful for unit testing and any other need you may think of. Features:.
Read more >Default props values in Storybook are not correct
However, there are no issues in a React project. For example, if I have a Button component: import React from "react"; ...
Read more >A complete guide to React default props - LogRocket Blog
In this article, we'll cover setting default props for React components. The ... If the prop is not specified when a component is...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Well this seems good and fits the documentation. Thanks a lot.
No big deal, all fixed now!