Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do I need to import react in every file?

Tags:

reactjs

I've found out that components without import React from 'react'; lines works well.

I've added import React from 'react'; to the first line of .jsx files conventionally. And I saw many open source with this line.

Then why do we add this line unnecessarily?

like image 441
tonwayer Avatar asked Aug 30 '25 14:08

tonwayer


1 Answers

You no longer need to import React from "react". Starting from the release 17 of React, JSX is automatically transformed without using React.createElement.
However, other exports like hooks must be imported.

like image 85
Tarek Hammami Avatar answered Sep 15 '25 06:09

Tarek Hammami



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!