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

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

Closed
codylawson opened this issue Nov 29, 2018 · 3 comments
Closed

Comments

@codylawson
Copy link

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.

@danez
Copy link
Collaborator

danez commented Dec 13, 2018

This was fixed in #311 and 3.0.0-rc.2. Can you try with this version?

@codylawson
Copy link
Author

@danez Confirmed to fix the issue I was seeing. This can be closed.

To followup though, it looks like the fix required a special handler for forwardRef as a known hoc. Does that mean all hoc's would need to be handled specially? Are custom hoc's not supported?

@eps1lon
Copy link
Contributor

eps1lon commented Dec 27, 2018

@codylawson forwardRef is not a HOC but a "normal" component. The issue was that forwardRef was not considered a component and therefore not eligible for HOC wrapping.

@danez It doesn't seem like #311 is included in 3.0.0-rc.2 which was merged with b048d58 into master. Any chance you can cut a release?

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 28, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants