'import ReactDOM vs. import { ReactDOM }

May be a stupid question.

import {ReactDOM} from 'react-dom/client'; // or import {ReactDOM as ReactDOM} are BAD
...
const root = ReactDOM.createRoot(document.getElementById("root"));

received error:

export 'ReactDOM' (imported as 'ReactDOM') was not found in 'react-dom/client' (possible exports: createRoot, hydrateRoot)

OK only import ReactDOM from 'react-dom/client'; This is different from this post



Solution 1:[1]

Apologies if I'm misunderstanding the question, but assuming I'm on point, the difference is how they are exported from the package.

ReactDOM is export default whereas the others (createRoot, hydrateRoot) are export only.

For more info: `export const` vs. `export default` in ES6

(and based on the fact that post has over 290 upvotes - not a silly question at all)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1