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.
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.
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.
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.
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.
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
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