ID photo of Ciro Santilli taken in 2013 right eyeCiro Santilli OurBigBook logoOurBigBook.com  Sponsor 中国独裁统治 China Dictatorship 新疆改造中心、六四事件、法轮功、郝海东、709大抓捕、2015巴拿马文件 邓家贵、低端人口、西藏骚乱
React function component version of react/ref-click-counter.html using useRef.
react/ref-click-counter-func.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>ref click counter</title>
<script src="https://unpkg.com/react@17/umd/react.development.js"></script>
<script src="https://unpkg.com/react-dom@17/umd/react-dom.development.js"></script>
<script src="https://unpkg.com/@babel/standalone@7.14.7/babel.min.js"></script>
</head>
<body>
<div id="root"></div>
<script type="text/babel">
function Main() {
  console.log('Main')
  const counterElem = React.useRef(null)
  return (
    <div>
      <button onClick={() => {
        console.log('onClick')
        const elem = counterElem.current
        elem.innerHTML = (parseInt(elem.innerHTML) + 1).toString()
      }}>
        Click me
      </button>
      <div
        ref={
          (elem) => {
            counterElem.current = elem
          }
        }
      >
        0
      </div>
    </div>
  )
}
ReactDOM.render( <Main/>, document.getElementById('root'))
</script>
</body>
</html>

Ancestors (12)

  1. React DOM manipulation
  2. React
  3. List of front-end web frameworks
  4. Front-end web framework
  5. Web framework
  6. Web technology
  7. Software
  8. Computer
  9. Information technology
  10. Area of technology
  11. Technology
  12. Home