📜  componentwillreceiveprops 挂钩 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:03:11.993000             🧑  作者: Mango

代码示例2
const { useState, useEffect, useMemo } = React;

function App() {
  const [count, setCount] = useState(50);

  useEffect(() => {
    setTimeout(() => {
      setCount(150);
    }, 2000);
  }, []);

  return ;
}

function DisplayCount(props) {
  const count = useMemo(() => props.count > 100 ? 100 : props.count, [props.count]);

  return 
{count}
; } ReactDOM.render(, document.getElementById("root"));