Skip to content

Support React.FC and companions #846

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

Merged
merged 5 commits into from
Sep 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions .changeset/cyan-ways-fry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
'react-docgen': major
---

`getTypeFromReactComponent` now returns an array of paths to types instead of
just one. This can appear when multiple type definitions are found for a
component, for example:

```ts
const Component: React.FC<Props> = (props: { some: string }) => {};
```

In this example both the `Props` definition as well as `{ some: string }` are
now found and used.

Here is a simple diff to illustrate the change when using
`getTypeFromReactComponent`:

```diff

const type = getTypeFromReactComponent(path)

-if (type) {
+if (type.length > 0) {
// do smth
}

```
6 changes: 6 additions & 0 deletions .changeset/eight-coats-tie.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'react-docgen': patch
---

Fix detection of react class components when super class is imported via named
import.
20 changes: 20 additions & 0 deletions .changeset/four-teachers-tan.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
'react-docgen': major
---

`resolveToValue` will not resolve to `ImportDeclaration` anymore but instead to
one of the possible specifiers (`ImportSpecifier`, `ImportDefaultSpecifier` or
`ImportNamespaceSpecifier`). This gives better understanding to which specifier
exactly `resolveToValue` did resolve a NodePath to.

Here is a possible easy fix for this in a code snippet that uses
`resolveToValue`

```diff
const resolved = resolveToValue(path);

-if (resolved.isImportDeclaration()) {
+if (resolved.parentPath?.isImportDeclaration()) {
// do smth
}
```
6 changes: 6 additions & 0 deletions .changeset/lazy-walls-swim.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'react-docgen': patch
---

Remove unnecessary call to `resolveToValue` when trying to find props type from
react components.
5 changes: 5 additions & 0 deletions .changeset/sour-jeans-tell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'react-docgen': minor
---

Add support for React.FC in TypeScript
Loading