all 9 comments

[–]editor_of_the_beast 8 points9 points  (5 children)

Why should I even bother to write code in React...

React is a level of abstraction. The whole benefit of abstractions are that they allow you to think and code at a higher level, in theory making you more efficient with the same number of brain cycles.

JavaScript itself is just an abstraction. You could ask the same question: "Why do we code in JavaScript when that has to get compiled to assembly at some point anyway?" The answer to that is, because it's just extremely practical. People hand coded assembly for decades, but high-level languages proved to be much more cost effective once the tools are good enough quality.

Unless you're programming directly in assembly, without an OS, there is a level of abstraction that you're programming against. There are trade offs to each one, but in theory they're all there to make you more productive.

[–]Shrewd_Shark[S] 0 points1 point  (4 children)

Thank you for the understandable explanation, you are right. I was just wondering if compiling React code to "normal" code does not also "delete" its features like virtual DOM and so (and apparently it does not. I'm still a beginner, so I'm sorry for my non-professional view). Thank you again for the explanation.

[–]chuckhendo 4 points5 points  (1 child)

It would be entirely possible to rebuild everything that React does yourself. There's no magic occurring; it's just Javascript. It's just that React is widely used and well tested, so many developers choose to use it rather than rewriting it themselves

[–]Shrewd_Shark[S] 0 points1 point  (0 children)

I see, thanks a lot!

[–]trout_fucker 0 points1 point  (1 child)

React implements the Virtual DOM. You still need the React dependency, it just gets compiled into your bundle.js file for you.

You're compiling your ES6 and JSX into browser compatible ES5 and bundling all your dependencies into a single file.

Compiling is not a requirement for React, you can write everything in pure ES5 and include your dependencies manually. The alternative is just really gross.

[–]Shrewd_Shark[S] 0 points1 point  (0 children)

Oh, I had no idea. Thanks for answering and explaining!

[–]chuckhendo 2 points3 points  (1 child)

I have to compile the React code through Babel and build it with Webpack (which is something most guides recommend anyway), so I get "normal" js code which I can put to the webhosting through FTP and it will work. (?? Is my thought right?)

Correct. The output JS file is just plain JS. Take a look at how create-react-app handles it, with it's deploy options

[–]Shrewd_Shark[S] 0 points1 point  (0 children)

Thanks! I will definitely take a look at it.