Reputation: 193312
After creating a site with create-react-app
, one sees that JSX gets rendered in the index.js file with the ReactDOM.render()
method.
How can it be, then, that JSX is still being parsed outside that method, as is shown here:
index.js:
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';
const jsxArray = [
<div>test</div>,
<div>test</div>,
<div>test</div>
];
console.log(jsxArray);
ReactDOM.render(
<React.StrictMode>
<App />
</React.StrictMode>,
document.getElementById('root')
);
Output in console:
Upvotes: 0
Views: 401
Reputation: 8412
Babel just compiles any valid syntax within the targeted file which match the plugin, it basically does not care if you put the syntax inside any valid Reactjs component or not.
So basically, you can set up any file with babel compiler
target to jsx it will return any jsx syntax within that file to a normal javascripts.
And it's also not necessary to be in any actual component to do that
You could try it here
Upvotes: 1