Do I need to import React for stateless functional components?

Yes, there is. Babel transpiles JSX to use React:

<div></div>

To:

React.createElement("div", null);

So your JSX is internally transpiled to use React.createElement in pure JavaScript, which does use React. Remember that JSX is just syntactic sugar over pure JavaScript. If you don’t specifically import it, it will report that React isn’t defined.

Update Sep 2021: In React 17, a new JSX transform is introduced which automatically transforms JSX without using React.createElement. This allows us to use JSX without importing React. More on docs

Leave a Comment

techhipbettruvabetnorabahisbahis forumuedusedueduseduedueduedusedueduedus