ID photo of Ciro Santilli taken in 2013 right eyeCiro Santilli OurBigBook logoOurBigBook.com  Sponsor 中国独裁统治 China Dictatorship 新疆改造中心、六四事件、法轮功、郝海东、709大抓捕、2015巴拿马文件 邓家贵、低端人口、西藏骚乱
react/prop-change-hook.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<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>
<p><a href="https://cirosantilli.com/react">https://cirosantilli.com/react</a></p>
<div id="root"></div>
<script type="text/babel">
function NotMain2(props) {
  console.log('NotMain2');
  const [n, setN] = React.useState(props.n)
  return (
    <>
      <div>NotMain2 props.n = {props.n}</div>
      <div>NotMain2 n = {n}</div>
    </>
  )
}

function NotMain(props) {
  console.log('NotMain');
  return (
    <>
      <div>NotMain props.n = {props.n}</div>
      <NotMain2 n={props.n} />
    </>
  )
}

function Main(props) {
  console.log('Main');
  const [n, setN] = React.useState(0)
  function handleClick() {
    console.log('handleClick\n');
    setN(n + 1)
  }
  return (
    <div>
      <div onClick={handleClick}>Click me twice</div>
      <div>Main n = {n}</div>
      <NotMain n={Math.floor(n / 2)}></NotMain>
    </div>
  )
}

ReactDOM.render(
  <Main/>,
  document.getElementById('root')
);
</script>
</body>
</html>