re: You don’t always need to import React VIEW POST

TOP OF THREAD FULL DISCUSSION
re: So here's a question I honestly don't know the answer to: why isn't import React from "react"; inserted at the transpilation step from jsx to js? ...
 

Thanks Alex, that's a great question I haven't considered.

Inserting the import statement would require a babel plugin (babel-plugin-react-require or babel-plugin-auto-import, etc), which could relieve us from having to manually insert it where JSX is used.

I honestly didn't know "why" babel doesn't import it automatically so dug around a bit.

It's to prevent import name resolution errors according to following closed issues.

The gist is that, importing react automatically can clash with other imports already declared as "React" or when "React" is declared globally in your application (using "script" tag).

code of conduct - report abuse