Does React really violate Separation of Concern by putting HTML and JS in a single file?View other answers to this thread
3.4K+ developers have started their personal blogs on Hashnode in the last one month.
Write in Markdown · Publish articles on custom domain · Gain readership on day zero · Automatic GitHub backup and more
No. Let's talk about browsers first. Browsers are used to render graphical elements like rects, circles, fonts, and some other shapes. In order to describe the stuffs we want to render we need to write code. There are mainly two ways in which you can tell a browser what to do:
- write in HTML, a text file of tags and contents
- write in DOM API, like
Here's a thing. User interfaces always requires lots of code and we will need abstractions for that. In HTML, people use nested tags, in DOM API, it's
Element.appendChild for example.
In the early days template engines are widely used. And in EJS there's
include to reusing small pieces of templates. It's very handy on HTML side, while creating UI in DOM API is slow and imperative. So, abstractions wins.