@cirosantilli/_file/react/react/ref-click-counter.html
New to topics? Read the documentation here!
@cirosantilli/_file/react/react/ref-click-counter.html by Ciro Santilli 34 Updated 2024-12-15 +Created 1970-01-01
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:we are extracing state from some random HTML string rather than having a clean JavaScript variable containing that value.
<button onClick={() => {
elem.innerHTML = (parseInt(elem.innerHTML) + 1).toString()
In this case we managed to get away with it, but this is in general not easy/possible.