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

Clarify how react should be imported in an ES6 environment #1258

Closed
wereHamster opened this issue Oct 15, 2018 · 1 comment
Closed

Clarify how react should be imported in an ES6 environment #1258

wereHamster opened this issue Oct 15, 2018 · 1 comment

Comments

@wereHamster
Copy link

The website carefully avoids mentioning how the "react" module should be imported, import React from … or import * as React from …. None of the code examples (that I was able to find) contain the import statement. Both import forms are used in the wild, but our tools disagree which one is correct:

  • The React source uses a default export, so the first form will become correct once React decides to provide the code as ES6 modules.
  • TypeScript declarations currently want you to use the second form, but you can enable a compiler option (allowSyntheticDefaultImports ) to allow it to accept the first form, for compatibility with CommonJS modules.
  • Flow recommends using the second form, but also allows the first form in some cases.

While I don't particularly care which form React decides on (though I dislike the default export because it makes it impossible to treeshake the module), it would be nice to document the "correct" way, so that we can already now prepare for the transition to React-as-true-ES-module.

@wereHamster
Copy link
Author

import * as React from 'react' is the way to do it.

facebook/react#18102

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

No branches or pull requests

1 participant