Skip to content

Add support for creating specs for React components that are exported as default #24929

@astone123

Description

@astone123

For the Create from React Component feature, we're using react-docgen to parse files and return any React components that are defined and exported. Unfortunately, this tool does not tell us whether a component is a named export or the default export.

This is a problem because when we create the spec file, we need to either import the component by name (import { MyComponent } from 'file') or by default (import DefaultComponent from 'file'). Right now, the spec template assumes that the component is a named export, so the spec will fail to run if it is exported by default.

There is also an edge-case with export { Foo as Bar } aliasing where react-docgen returns information about Foo but import {Foo} from '...' would not work correctly.

We should be able to use a custom resolver with react-docgen to add information to the response about whether each component is a named or default export. We should then be able to use this information to craft the correct import statement in the generated spec file.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions