There are at least a few issues wrong with your code:
You don’t have a CDN to Babel referenced in your HTML. Babel needs to be “installed” in order for you to use JSX in your React code.
Your “reactfile.js” needs to be a JSX file, not a regular JS file.
The first argument to ReactDOM.render() needs to be a component, not regular HTML.
It also no longer works to load an HTML file directly in your browser. That used to work with React 15, but has since been deprecated due to CORS issues. You need to run a basic HTTP server now. You can use the one built into either Python (SimpleHTTPServer), or Node.js (https://www.npmjs.com/package/http-server).
If you don’t understand what Babel or JSX is, I’d recommend using Google. Also this is a good free starter resource for learning React that’s more accessible than the official docs: https://flaviocopes.com/page/react-handbook/
Once you understand the basic concepts and know how to set up a basic React app directly via the browser, I’d recommend learning Node.js and create-react-app. It vastly simplifies everything.
Thanks for that , I’ll take a look at it all
I started with some beginners course on React on youtube but it was from 2016 and didn’t explain anything about setup.
The current version of React is 16 which came out in September 2017, so I’d recommend not learning from any resources dated before then, which will refer to React 15. 15 is obsolete; see the link below for info on how naming in software is basically versioned. Anytime software gets updated to a new major version, stuff inevitably breaks, and you have to learn most things anew.
Thanks for the reply astv99
I started reading the book in the link you suggested, and
very early on it says the react file should be a .js file (with text/bable mime type), so I’m confused why you said my “reactfile.js” needs to be a JSX file?
Sorry if I’m asking too much ,I’m just a bit confused ,hope you don’t mind
It seems like the file extension doesn’t matter as far as getting things actually working. I just tried that and it looks like it runs whether the file is JS or JSX.
But JavaScript files containing React code should still be in JSX format regardless, so I’d consider that an oversight on the author’s part. It’s better to do it that way in your code editor for syntax highlighting.
If you’re coding on Windows, which I assume you are from the Notepad++ reference, you need to run Command Prompt as an Administrator. Or I’d recommend using this: https://cmder.net/
I’ve been at this coding thing for a while myself. Btw if you’re still using Notepad++, I’d recommend using this instead: https://code.visualstudio.com/
Notepad++ is fine as a general-purpose editor but since it doesn’t have syntax highlighting for React, you should use something that does.
Edit: never mind, I’ve decided to finish reading my JS and Jquery books , and spend more time learning those two before I start with React.
I will revive this thread when I need help again, thanks
So now I’m stuck again.
I managed to get to the point where I run “npm start” in the node.js cmd prompt .
When I open the file I created through " npx react-create-app todolist" , todolist (it’s under windows32), I see a list of files , with no index.html file.?
I was following a tutorial on youtube that used visual studio and they had a index.html (with an id of root) ? I’m also reading a react book but it hasnt’ explained this yet.
Do I need visual studio for this to work, or do I use my own index.html file that I add to this system32/todolist file? And do I edit the js /css files that are in this list if I want to code react?
You should not create the app inside system folders, that is a really bad idea. That happened because you ran the Node.js command prompt as admin. Doing that will open it up inside the System32 folder. Install the app inside a “normal” user folder.
The index.html file is inside the public folder.
Install the app using create-react-app into a folder of your choice.
Steps (there are different ways to do it, this is just one way)
Create a “projects” folder inside your “Documents” folder
Create a “todolist” folder inside “projects” folder
Right-click the “todolist” folder and from the right-click menu select “Open with Code”
Inside VS Code open the build-in terminal. From the menu View select Terminal, take note of the hotkey in the menu so you can use that instead of from now on
Run npx create-react-app . (using . will create an app using the current folder name as the app name, i.e. todolist).
Visual Studio and Visual Studio Code (VS Code) are not the same programs. You do not need any of them to write React code but I would suggest using VS Code anyway.
As for how, and where to write the code you are better off looking at some React crash course articles and videos.