Skip to content

Description null for properties of components wrapped in forwardRef HOC #312

Closed
@codylawson

Description

@codylawson

Seeing an issue where wrapping a component in forwardRef results in the descriptions resolving to null.

Works:

import PropTypes from 'prop-types';
import React from 'react';

const Label = ({ children, ...other }) => {
  return <div {...other}>{children}</div>;
};

Label.propTypes = {
  /** Content of the label */
  children: PropTypes.node,
  /** Blue style label */
  blue: PropTypes.bool,
  /** Green style label */
  green: PropTypes.bool,
  /** Yellow style label */
  yellow: PropTypes.bool,
  /** Red style label */
  red: PropTypes.bool
};

Label.defaultProps = {};

export default Label;

Broken:

import PropTypes from 'prop-types';
import React, {forwardRef} from 'react';

const Label = forwardRef(({ children, ...other }, ref) => {
  return <div {...other} ref={ref}>{children}</div>;
});

Label.propTypes = {
  /** Content of the label */
  children: PropTypes.node,
  /** Blue style label */
  blue: PropTypes.bool,
  /** Green style label */
  green: PropTypes.bool,
  /** Yellow style label */
  yellow: PropTypes.bool,
  /** Red style label */
  red: PropTypes.bool
};

Label.defaultProps = {};

export default Label;

It's interesting that the rest of the prop definition exists and only the description is dropped. Is this a known issue? It seems slightly different from other issues related to HOC in that even if the component name is resolved correctly, the prop definition is not complete.

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