组件为什么每次挂载和更新都渲染了两次函数

来源:3-6 在函数组件使用 state - useState Hook

慕粉3775984

2020-08-24

const LikeButton: React.FC = () => {
  const [like, setLike] = useState(0);
  console.log('LikeButton reader');
  return (
    <div>
      <button
        onClick={() => {
          setLike(like + 1);
        }}
      >
        {like}?
      </button>
    </div>
  );
};

首次挂载和更新都会执行两次log函数

写回答

2回答

张轩

2020-08-25

同学你好 常见问题中有这个问题欧: https://coding.imooc.com/learn/questiondetail/176598.html

0
1
慕粉3775984
非常感谢!
2020-08-28
共1条回复

慕粉3775984

提问者

2020-08-24

https://coding.imooc.com/learn/questiondetail/176598.html

0
0

React18+TS高仿AntD从零到一打造组件库

设计,开发,测试,发布再到 CI/CD,从0到1造轮子

2124 学习 · 959 问题

查看课程