Does React really violate Separation of Concern by putting HTML and JS in a single file?

View other answers to this thread
Start a personal dev blog on your domain for free and grow your readership.

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

Daron Robinson's photo

In the context of the browser, JS and HTML are joined at the hip through the DOM. This whole SoC debate is merely a side effect of the fact that HTML was conceived as a static layout language, an extension of passive document markup languages like SGML. Javascript was only (hastily) added after the fact to increase utility and interactivity once it became plain that the web could be more than linked documents.

So Javascript was created to make up for deficiencies in the original vision of an HTML based web, and this is reflected in its DOM centric nature, it's mainly there to tweak the view and user experience, not to do arbitrary programming tasks or pure mathematics (sorry Node).

This was not an inevitable or even an ideal outcome. It was an unfortunate historical accident. React just puts the two 'concerns' together in a way that feels natural and minimises pointless friction in practice.