Home > Enterprise >  Why React can't be written as react
Why React can't be written as react

Time:01-25

Problem described here too, but the response was not elaborative React can't be found

import React from 'react' <- I know this statement is correct

Since, "React" is a default export and not a named export therefore, below statement should work too

import react from 'react'

I know React.createElement() will be called in future, but why isn't react.createElement() correct; afterall the word "React" is just a name to refer to 'react' module

CodePudding user response:

In the old versions of react-scripts which uses webpack as a bundler, you need to define a React object in your code where you use JSX because when the bundler is handling your code uses the defined React object to call for the nessecerary methods like React.createElement and everywhere else that react is needed. That is why if you remove the React import or write the name in any other fashion you will face an error

  •  Tags:  
  • Related