3 ms·
Has anyone wondered how similar in spirit React is to the way html and js were originally meant to be written (with embedded callbacks, e.g. `<a href=bla onClic
by why-el 11y ago
Has anyone wondered how similar in spirit React is to the way html and js were originally meant to be written (with embedded callbacks, e.g. `<a href=bla onClick='myfynction>`)? Isn't the `a` in some sense a React component with explicit and local state changes, only missing a explicit render? Theoretically one could build on top of this to make Angular/React style custom components without the need to re-invent state management code.
Of course, I am missing many good features of React (due to my lack of understanding, as I am not a front end developer), but at least conceptually one could argue the original idea was there all along. Perhaps the real power of React lies in the excellent diff algorithm they came up with. Any thoughts?
- pluma 11y agoThe 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.