Every story and comment from the Hacker News API, in a layout borrowed from 2001.
A comment on React is becoming a black box. Parent comment
also, you shouldn't use useState unless you want it to rerender, which you don't because you're printing to console. use a ref instead for myNumber.
the problem you are trying to solve, updating a number if someone clicks on something, is already solved in React:
const HelloComponent => React.forwardRef((props, forwardRef) => { const myNumber = useRef(0) const printToConsole = () => { myNumber.current = myNumber.current + 1 console.log("My Number:", myNumber.current) } render ( <div ref={forwardRef} onClick={printToConsole}>click me</div> ) }
There are no comments on this comment yet.
also, you shouldn't use useState unless you want it to rerender, which you don't because you're printing to console. use a ref instead for myNumber.
the problem you are trying to solve, updating a number if someone clicks on something, is already solved in React:
then you can simply trigger a click by calling .click() on the forwarded ref wherever you happen to mount it.