Doesn't detect stateless functional components that return ternary expressions
See original GitHub issueGiven a component defined like this:
import React from 'react';
export default function Button(props) {
const button = <input type="button" />;
return props.next ? <div id="next">{button}</div> : button;
}
Button.propTypes = {
next: React.PropTypes.bool,
};
I get this error: Error: No suitable component definition found.
A workaround for this is not to use a ternary:
import React from 'react';
export default function Button(props) {
const button = <input type="button" />;
if (props.next) {
return <div id="next">{button}</div>;
}
return button;
}
Button.propTypes = {
next: React.PropTypes.bool,
};
This gives me the correct output:
{
"description": "",
"methods": [],
"props": {
"next": {
"type": {
"name": "bool"
},
"required": false,
"description": ""
}
}
}
Supporting ternary statements would be nice since I have a lot of them in my codebase.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:7
- Comments:13 (5 by maintainers)
Top Results From Across the Web
If-else in React Stateless functional components
New code: Now, how should I check the else condition in case the state of currentUser is false. As you can see right...
Read more >Loading State Trick for Stateless Functional Components in ...
I removed the implicit return from the DisplayItems function, and then used a ternary operator to determine which component gets rendered. If ...
Read more >Nested Ternary statements in React JSX - DEV Community
Nested Ternary statements in React JSX ... found to this is to extract the second part of the ternary into a stateless functional...
Read more >Conditional Rendering in React using Ternaries and Logical ...
Here's a Stateless Function Component (SFC) that does just that. const MyComponent = ({ name }) => { if (name) { return (...
Read more >Use a Ternary Expression for Conditional Rendering - React
In this React tutorial we use a ternary expression for conditional rendering. This video constitutes one part of many where I cover the ......
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 Free
Top 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
Does this issue still need a fix? I still see issues if I do a ternary or
bool && <div />
.@bregenspan Looks like it’s fixed on our end, thanks!