Member-only story
Why ‘React’ should be imported when not used?
Whenever we consume a variable, we either need to declare in the same file or we need to import from a file that has been declared and exported
The above examples have the logic as we are using tax in our file so we expect that to be declared, but why React we are expected to import React when we are not using it?
It is because JSX (Javascript extension to have HTML in JS file) will not be understood by browser, so we need to convert in to ones(HTML, CSS, Javascript) which browser can understand.
So even though we are not directly consuming React, when converted to plain JS while bundling, it will use React.createElement method to create actual DOM
So we need to import React whenever HTML syntax is used in JS file.
If you don’t use HTML in JS, we don’t need to import React.