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

Will Cameron's photo

This comes up at work a bit with the React skeptics. I like the way @vasan put it - separating HTML and JS is separation of technologies, not separation of concern. The JS we write in the browser is there because we need to dynamically interact with the DOM. JS is concerned with HTML, and they are inextricably linked. I see something like templates as an intermediary, linking small chunks of HTML with data, whereas React takes that to the next logical step - linking state, lifecycles, and all view logic with the small, specific, manageable chunks of "DOM" and composing those as necessary. I personally love JSX because we can write views in a way that is much easier to reason about than document.createElement("x"), you just create the element: <x>{composable}</x>.