javascript – Why do I need to import React from ‘react’ in the index.js file when it’s not neccessary to import react anymore?

I am learning React.js . I saw that after version 17 it’s no longer needed to import React anymore. My currrent react version is v18.2.0 . I am using this code :

// import React from 'react';
import ReactDOM from 'react-dom/client';
import './index.css';
import App from './App';

const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(
  <React.StrictMode>
    <App />
  </React.StrictMode>
);

I am getting this error:

Failed to compile.

[eslint]
src\index.js
Line 8:4: ‘React’ is not defined react/jsx-no-undef

Search for the keywords to learn more about each error.
ERROR in [eslint]
src\index.js

Line 8:4: ‘React’ is not defined react/jsx-no-undef

Search for the keywords to learn more about each error.

webpack compiled with 1 error

Do I have to import React from ‘react’? What can I do to avoid this error ?
Please don’t downvote my post.

I have commented out the import React from 'react'; line and I am getting the error mention above.

I expect my code to compile successfully..

Read more here: Source link