hipstersmoothie / storybook-addon-react-docgen

A storybook addon to display react docgen info.
MIT License
87 stars 14 forks source link

React Hook + Memo support #5

Open brandon-pereira opened 5 years ago

brandon-pereira commented 5 years ago

Hey! Love the addon!

I'm getting a proptype warning when using with React hooks.

My component:

const Navigation = React.memo((props) => {
  return (<div />);
});

Navigation.defaultProps = {
  routes: []
};
Navigation.propTypes = {
  routes: PropTypes.array
};

logs warning:

checkPropTypes.js:19 Warning: Failed prop type: Invalid prop `type` of type `object` supplied to `PropTable`, expected `function`.
    in PropTable
    in Unknown
    in div
    in div
    in div
    in div
    in div
    in Story

When I remove the React.memo() wrapper around my component, the warning goes away.

I'm open to helping resolve the issue if needed. It seems to be like a prop warning (proptable is rendering fine) so maybe we can just make the prop type more generic?

brandon-pereira commented 5 years ago

Actually, an update on this.. it seems the displayName is being stripped UNLESS I also add PropTypes.displayName = 'navigation'. But, thats not a problem.. I've updated my generator to automatically add this.

hipstersmoothie commented 5 years ago

@brandon-pereira any chance i could get a full reproduction repo to play around with?

zach-aries commented 5 years ago

I'm also having this issue when wrapping components in React.memo(). Note that for me, my 'propTypes' column disappears.

Screen Shot 2019-03-27 at 3 43 00 PM

hipstersmoothie commented 5 years ago

@zach-aries example repo would be 🔥