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.

Doesn't detect stateless functional components that return ternary expressions

See original GitHub issue

Given 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:closed
  • Created 7 years ago
  • Reactions:7
  • Comments:13 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
mike-robertsoncommented, Feb 28, 2017

Does this issue still need a fix? I still see issues if I do a ternary or bool && <div />.

0reactions
caseycallowcommented, Jul 2, 2018

@bregenspan Looks like it’s fixed on our end, thanks!

Read more comments on GitHub >

github_iconTop 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 >

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