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

Cannot render component through higher order component #65

Closed
edwilliams opened this issue Jun 20, 2018 · 9 comments
Closed

Cannot render component through higher order component #65

edwilliams opened this issue Jun 20, 2018 · 9 comments
Labels
bug Something isn't working

Comments

@edwilliams
Copy link

Bug Report

Cannot render component through higher order component

while exporting a component directly works fine, if a component is exported via a higher order component then the PropType table does not render

To Reproduce

  1. set PropType (e.g. SubTitle.propTypes = { error: PropTypes.bool })
  2. export component as via higher order component (e.g. export default HOC(SubTitle))
  3. PropType table does not appear
// basic HOC() for demonstration
import React from 'react'
export default (HOC) => {
  return class ReactHOC extends React.Component {
    render() {
      return <HOC {...this.props}/>
    }
  }
}

Enviroment

  • OS: OSX 10.13.3
  • Node: v8.9.4
  • NPM: v6.0.1
@pedronauck pedronauck added the bug Something isn't working label Jun 20, 2018
@pedronauck
Copy link
Member

This is something relative to babel-plugin-react-docgen, I tried to find some resolutions but I didn't get any results 😢

@diegohaz
Copy link
Contributor

diegohaz commented Jul 7, 2018

https://github.com/diegohaz/parse-prop-types can possibly help with that.

@pedronauck
Copy link
Member

pedronauck commented Jul 7, 2018

But I need something that parses typescript and flow too @diegohaz, your package can do that?

@diegohaz
Copy link
Contributor

diegohaz commented Jul 7, 2018

It doesn't. Unless there's something that transforms flow/typescript into PropTypes.

@joekarasek
Copy link

joekarasek commented Jul 10, 2018

I've been searching for a solution around transforming between various schema declarations (proptypes, flow, json schema, typescript) with little luck. Ended up baking my own for a project. However, this is the most promising library I have found to date that will automate moving from one to the other.

https://www.npmjs.com/package/shapeshifter

However, its trickier than it seems as the specs for each don't cleanly line up with each other (for example JSON Schema doesn't support functions).

@Florian-Guillot-Axa
Copy link

I have the same problem, and I was thinking about this :

class _Button extends React.Component {
  render() {
    return(<button>{this.props.children}</button>)
  }
}

const Button = HOC(_Button)

Button.propTypes = {
  children: PropTypes.string
}

export default Button

But it doesn't render PropsTable too. Is it related ?

@popkirby
Copy link

popkirby commented Aug 1, 2018

For plain ES / Flow, react-docgen recognizes HOC, but outputs type information for base components. (In SubTitle example, SubTitle component will get type information, but HOC(SubTitle) component will not.)

I think it is needed to extend findAllExportedComponentDefinitions resolver to treat HOC(Component) as a React component.

@nicholasess
Copy link
Contributor

We are thinking about our structure to support HOC, because the DataServer parse just Components and docgen has a specific function to parse HOC.

@pedronauck
Copy link
Member

pedronauck commented Sep 11, 2018

I'll close this since it will be also fixed with #240 when we can pass custom config to react docgen

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

7 participants