3 ms·
The power is that it behaves within the scopes of your JavaScript code. "onclick" in HTML can only refer to the global scope. In React it's within the scope the
by pluma 11y ago
The power is that it behaves within the scopes of your JavaScript code. "onclick" in HTML can only refer to the global scope. In React it's within the scope the element is defined in.
But the more poignant observation about React is that the components aren't actually anything like templates. You can think of React components as descriptions of the structure of the DOM -- if the equivalent structures in the DOM already exist[1], they are just "progressively enhanced" when you run React on them. The only reason you would want to generate that HTML on the server with React instead of writing that HTML yourself is that it avoids unnecessary duplication.
[1]: currently React needs to add proprietary attributes to identify markup generated by React but this will be made redundant in an upcoming version.