Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why ReactJS way of mixing code with HTML is a better design?

How is reactjs way of mixing code with html a better design?
All the time we think of separating HTML+CSS+Javascript to keep separation of concerns and to improve re-usability, maintainability.
Why go back and mix all these together?
It almost sounds as good as rolling back regulations on environment and there will always be some people who will justify it tooth & nail.

like image 880
Winter Melon Avatar asked Sep 22 '19 05:09

Winter Melon


People also ask

Can you mix React with HTML?

Sure it's ok. all in all it's HTML in the end. React components are set of html elements when you call the render function.

Why ReactJS is better than HTML?

What makes React such a desirable library to learn is that it doesn't replace HTML. It takes advantage of HTML's popularity and strength as the most popular programming language, by letting you use a very similar syntax to HTML to build interfaces and add dynamic features to it using JavaScript.

Why we use HTML in React?

With React, we write HTML using JavaScript. We rely on the power of JavaScript to generate HTML that depends on some data, rather than enhancing HTML to make it work with that data. Enhancing HTML is what other JavaScript frameworks usually do.

Why ReactJS is better?

One of the main benefits of using React JS is its potential to reuse components. It saves time for developers as they don't have to write various codes for the same features. Furthermore, if any changes are made in any particular part, it will not affect other parts of the application.


1 Answers

Not sure if it's a better design, but in the Introducing JSX section of the React docs, the same question is posed: Why JSX?

The reason the developers behind React prefer having JSX inside the component is that React assumes that the rendering logic is deeply related to event handling, state change, and so on, so instead of separating these two by putting JSX and logic in separate files, React separates concerns and keep the same concern inside one unit called component.

Instead of artificially separating technologies by putting markup and logic in separate files, React separates concerns with loosely coupled units called “components” that contain both. https://reactjs.org/docs/introducing-jsx.html

The docs suggest a talk by Pete Hun on Rethinking best Pratices, which might shine some light into the discussion: https://www.youtube.com/watch?v=x7cQ3mrcKaY

like image 160
Elder Patten Ferreira Avatar answered Nov 07 '22 05:11

Elder Patten Ferreira