Skip to content

Stateless component with HOC expected syntax #129

@aweber1

Description

@aweber1

Hi,

I have a stateless component wrapped in a HOC written like this:

import React, { PropTypes } from 'react';
import extendStyles from 'enhancers/extendStyles';

const Test = props =>
  <div style={props.style}>
    Hello world!
  </div>;

Test.propTypes = {
  style: PropTypes.object,
};

export default extendStyles(Test);

Unfortunately, when I try to parse it I get Error: No suitable component definition found.

If I remove the HOC, the component is parsed.

My HOC looks like this:

import React, { PropTypes } from 'react';
import deepExtend from 'deep-extend';

export default (WrappedComponent, styles = {}) => {
  const Enhancer = (props) => {
    const computedStyles =
      typeof styles === 'function' ?
      styles(props) :
      styles;
    const style = deepExtend({}, computedStyles, props.style);
    return <WrappedComponent {...props} style={style} />;
  };

  Enhancer.propTypes = {
    style: PropTypes.object,
  };

  Enhancer.defaultProps = {
    style: {},
  };

  Enhancer.displayName =
    WrappedComponent.displayName ||
    WrappedComponent.name ||
    'Component';

  return Enhancer;
};

I'm not sure how I can change the code so that docgen will parse it. I'm open to making changes in the HOC, but would rather not change the way the component is written if possible.

Sorry for the code dump, but hoping it will help in repro or someone will see something obvious.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions