How to NOT import React with 3.3.0?

before

{
  "plugins": [
    [
      "@babel/plugin-transform-react-jsx",
      {
        "runtime": "automatic"
      }
    ]
  ]
}

3.3.0

import React from 'react'

import '../imports/client'

window.React = React

Is it possible to avoid a global assign?

Do you mean using SWC with modern: true enabled?

Have you checked the docs? There’s a specific config that does the same as @babel/plugin-transform-react-jsx.

Why do you need this part?

so you don’t have to write import React from 'react' on every single jsx file.

Then you may have a bunch of other problems with the editor, type check…

I don’t see any problems in Webstorm and got the idea from a Visual Studio forum or so. You still need to import the named imports from React though, such as useState, useEffect…

It’s very annoying to import each file individually, and there was an early bug where doing so caused the page to load very slowly during project growing.

framework like next.js doesn’t have this issue, i think its okay. cursor, other vscode fork doesn’t have such issue.

yes, i have modern enabled.
let me find out

wowzer, it works~



1 Like