Which statement shows how to import React and ReactDOM?

Master ReactJS with our comprehensive test. Practice with multiple-choice questions and detailed explanations. Build your skills for the exam with our engaging format and expert tips!

Multiple Choice

Which statement shows how to import React and ReactDOM?

Explanation:
Importing the libraries you use at the top of a React file is how you bring in the tools you need. To use React and render into the DOM, you commonly import the default export from 'react' as React and the default export from 'react-dom' as ReactDOM. The statement with both imports shown as separate lines is the valid approach: import React from 'react'; followed by import ReactDOM from 'react-dom'; This ensures both modules are available in your file. Using only one of them would leave the other tool unavailable, so the single-line option doesn’t meet the requirement. And trying to combine them in one line with an and (import React from 'react' and ReactDOM from 'react-dom') isn’t valid ES module syntax, since you can’t mix two default imports in one statement. Context: in many React setups, React is the library responsible for creating elements, while ReactDOM handles rendering those elements into the DOM. So you need both imports to work with typical React apps.

Importing the libraries you use at the top of a React file is how you bring in the tools you need. To use React and render into the DOM, you commonly import the default export from 'react' as React and the default export from 'react-dom' as ReactDOM. The statement with both imports shown as separate lines is the valid approach: import React from 'react'; followed by import ReactDOM from 'react-dom'; This ensures both modules are available in your file.

Using only one of them would leave the other tool unavailable, so the single-line option doesn’t meet the requirement. And trying to combine them in one line with an and (import React from 'react' and ReactDOM from 'react-dom') isn’t valid ES module syntax, since you can’t mix two default imports in one statement.

Context: in many React setups, React is the library responsible for creating elements, while ReactDOM handles rendering those elements into the DOM. So you need both imports to work with typical React apps.

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy