mirror of
https://github.com/storybookjs/storybook.git
synced 2025-04-01 05:05:25 +08:00
Addon-docs: Fix React.forwardedRef/memo props (#8445)
Addon-docs: Fix React.forwardedRef/memo props
This commit is contained in:
commit
93d9608493
@ -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);
|
||||
};
|
||||
|
@ -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' };
|
@ -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' };
|
Loading…
x
Reference in New Issue
Block a user