Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problems with stateless functional components that return null #368

Closed
robcaldecott opened this issue Mar 31, 2017 · 1 comment
Closed
Labels

Comments

@robcaldecott
Copy link

I'm using v5 with create-react-app 0.9.5 which does not like one of my stateless functional components that returns null using a ternary based on a prop setting (a pattern that is common with material-ui components.)

Warning: src\MyComponent.js matches a pattern defined in ”components” or “sections” options in your style guide config but doesn’t export a component.

An example component looks something like this:

import React, { PropTypes } from "react";

const MyComponent = props => {
  return props.isVisible ? <p>Test</p> : null;
};

MyComponent.propTypes = {
  isVisible: PropTypes.bool
};

MyComponent.defaultProps = {
  isVisible: true
};

export default MyComponent;

If I change the code to look like this then it works and includes my component:

const MyComponent = props => {
  if (props.isVisible) {
    return <p>Test</p>;
  }
  return null;
};

Not a big deal but a little odd all the same. :)

@sapegin
Copy link
Member

sapegin commented Apr 2, 2017

Looks like react-docgen doesn’t support it. It’s hard to detect all possible ways of defining stateless components without false positives (which would be worse — in your case you could just rewrite the component).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants