Currently I can only use .js files, in case I try to use .jsx, this will cause an error. Here's the problem: I usually use code formatters, and writing jsx and formatting in js files, causes the code to be completely out of order, also causing syntax errors.
I am new to React, so I do not know how to configure to use jsx files, at least in other than the main files (index.js).
I've seen about the eject script, but there seem to be some drawbacks in using this.
Is there any solution for using jsx files without running "npm run eject"?
EDIT: The error is something like, "Could not import XXX file from filename.js", that is, when I try to import from a filename.jsx file, it searches only for filename.js files, and as there is no file. js, I can not care.
EDIT2: As said in a comment, just reboot the server, and I think I was changing from js to jsx when the server was already running, now I've changed and rebooted and it seems to be working
While React can be used without a build pipeline, we recommend setting it up so you can be more productive. A modern build pipeline typically consists of: A package manager, such as Yarn or npm. It lets you take advantage of a vast ecosystem of third-party packages, and easily install or update them.
JSX is not a requirement for using React. Using React without JSX is especially convenient when you don't want to set up compilation in your build environment. Each JSX element is just syntactic sugar for calling React. createElement(component, props, ...children) .
Open a terminal on vscode, then make sure you already node installed. Type npm install after that npm run start or whatever command to run, you can see on package. json . Save this answer.
React doesn't require using JSX, but most people find it helpful as a visual aid when working with UI inside the JavaScript code. It also allows React to show more useful error and warning messages.
.jsx
works out of the box with create react app.
You are changing the extensions while the server is running, so the server thinks that you are referencing a file that does not exists anymore since it resolves the file as .js
initially and keeps that extension, is like deleting a file and trying to import it, the same error is displayed, reboot the server and everything should work as expected.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With