Skip to content
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

Add Destructure Named Imports Option for update-react-imports #278

Merged
merged 1 commit into from
Oct 9, 2020

Conversation

lunaruan
Copy link
Contributor

We originally did not destructure named imports because it was pointed out to us that some people might want to keep the import * as React from 'react' option. However, this issue points out that there are codebases that would prefer to use destructured named imports (ex. import {useState} from 'react') instead now that React no longer needs to be in scope to use JSX. This PR introduces an option to the transform that allows people to choose to destructure named imports as well as default imports.

Copy link
Contributor

@threepointone threepointone left a comment

Choose a reason for hiding this comment

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

Missed this, sorry! Looks good to me, approving and merging. Please ask dan to do a publish.

@threepointone threepointone merged commit bb676bd into reactjs:master Oct 9, 2020
@@ -147,6 +147,10 @@ npx react-codemod sort-comp <path>

[As of Babel 7.9.0](https://babeljs.io/blog/2020/03/16/7.9.0#a-new-jsx-transform-11154-https-githubcom-babel-babel-pull-11154), when using `runtime: automatic` in `@babel/preset-react` or `@babel/plugin-transform-react-jsx`, you will not need to explicitly import React for compiling jsx. This codemod removes the redundant import statements. It also converts (`import React from 'react'`) to named imports (`import * as React from 'react'`).

The wizard will ask for 1 option -

* **Destructure named imports?**: Destructures named imports (import * as React from 'react') as well as default imports. Does not do this by default.
Copy link
Member

Choose a reason for hiding this comment

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

Nit: These are "namespace imports", not "named imports". Named imports are what destructuring converts them to.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants