atlassian / extract-react-types

One stop shop for documenting your react components.
https://atlassian.github.io/extract-react-types/
MIT License
179 stars 28 forks source link

Add support for FC<Props> #136

Closed danieldelcore closed 3 years ago

danieldelcore commented 4 years ago

Components typed using FC from @types/react should be supported.

elisechant commented 4 years ago

Confirming this is an issue, and a priority to fix.

For:

<Props
  props={require('!!extract-react-types-loader!../src/my-component')}
/>

/src/my-component Works:

import React from 'react';
interface Props {
  title: string;
}
export default ({
  title,
}: Props) => (
  <p>Hello</p>
)

Does not work, but should:

interface Props {
  title: string;
}
const EmptyState: React.FC<Props> = ({
  title,
}) => (
  <p>Hello</p>
);
export default EmptyState;
elisechant commented 4 years ago

This can be worked around for the time being, by adding an additional file:

./src/my-component/index.tsx

#export interface Props {
  title: string;
}
const EmptyState: React.FC<Props> = ({
  title,
}) => (
  <p>Hello</p>
);
export default EmptyState;

👇 ./src/my-component/_atlaskit-docs-props.tsx

import { Props } from './my-component';
export default (arg: Props) => null

And importing this file instead, ie

<Props
  props={require('!!extract-react-types-loader!../src/my-component/_atlaskit-docs-props')}
/>