DEV Community

Discussion on: You don’t always need to import React

Collapse
 
dance2die profile image
Sung M. Kim • Edited

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).