Skip to content

Commit

Permalink
Addon-docs: Fix React.forwardedRef/memo props (#8445)
Browse files Browse the repository at this point in the history
Addon-docs: Fix React.forwardedRef/memo props
  • Loading branch information
shilman authored Oct 19, 2019
2 parents e86cbac + d163699 commit 93d9608
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
14 changes: 12 additions & 2 deletions addons/docs/src/lib/getPropDefs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,5 +84,15 @@ const propsFromPropTypes: PropDefGetter = type => {
return Object.values(props);
};

export const getPropDefs: PropDefGetter = type =>
hasDocgen(type.__docgenInfo) ? propsFromDocgen(type) : propsFromPropTypes(type);
export const getPropDefs: PropDefGetter = type => {
let processedType = type;
if (type.render) {
processedType = type.render().type;
}
if (typeof type.type === 'function') {
processedType = type.type().type;
}
return hasDocgen(processedType.__docgenInfo)
? propsFromDocgen(processedType)
: propsFromPropTypes(processedType);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import React from 'react';
import DocgenButton from '../../components/DocgenButton';

const ForwardedButton = React.forwardRef((props, ref) => <DocgenButton ref={ref} {...props} />);

export default {
title: 'Addons|Docs/ForwardRef',
component: ForwardedButton,
};

export const displaysCorrectly = () => <ForwardedButton>Hello World!</ForwardedButton>;
displaysCorrectly.story = { name: 'Displays forwarded ref components correctly' };
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import React from 'react';
import DocgenButton from '../../components/DocgenButton';

const ButtonWithMemo = React.memo(props => <DocgenButton {...props} />);

export default {
title: 'Addons|Docs/ButtonWithMemo',
component: ButtonWithMemo,
};

export const displaysCorrectly = () => <ButtonWithMemo>Hello World!</ButtonWithMemo>;
displaysCorrectly.story = { name: 'Displays components with memo correctly' };

1 comment on commit 93d9608

@vercel
Copy link

@vercel vercel bot commented on 93d9608 Oct 19, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.