@cirosantilli/_file/react/react/ref-click-counter.html Updated +Created
Dummy example of using a React ref This example is useless and to the end user seems functionally equivalent to react/hello.html.
It does however serve as a good example of what react does that is useful: it provides a "clear" separation between state and render code (which becomes once again much less clear in React function components.
Notably, this example is insane because at:
<button onClick={() => {
  elem.innerHTML = (parseInt(elem.innerHTML) + 1).toString()
we are extracing state from some random HTML string rather than having a clean JavaScript variable containing that value.
In this case we managed to get away with it, but this is in general not easy/possible.
React Updated +Created
Website: reactjs.org
React officially recommends that you use Next.js[ref], so just do it. It just sets up obvious missing functionality from raw React.
React feels like a good. But it also feels impossible to use/learn sometimes.
Its main design goal is to reduce DOM changes to improve rendering times.
And an important side effect of that is that it becomes easier to do stuff of the type:
  • user creates a new comment that appears on screen without page reload
  • comment has a delete button, which is JavaScript callback activated
and then the new comment easily gets the callback attached to it.
And it also ends up naturally doubling as a template engine.
But React can also be extremely hard to use. It can be very hard to know what you can and cannot do sometimes, then you have to stop and try to understand how react works things better:The biggest problem is that it is hard to automatically detect such errors, but perhaps this is the same for other frontend stuff. Though when doing server-side rendering, the setup should really tell you about such errors, so you don't just discover them in production later on.
Is is also very difficult to understand precisely why hooks run a certain number of times.
Examples under: react.
Video 1.
React for the Haters in 100 Seconds by Fireship (2022)
Source.
React class vs function component Updated +Created
React function components do produce shorter code. But they are also impossible to understand without knowing what is their corresponding class component.
Hooks were introduced much after classes, and just require less code, so everyone is using them now instead of classes.