组件为什么每次挂载和更新都渲染了两次函数
来源: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回答
-
同学你好 常见问题中有这个问题欧: https://coding.imooc.com/learn/questiondetail/176598.html
012020-08-28 -
慕粉3775984
提问者
2020-08-24
https://coding.imooc.com/learn/questiondetail/176598.html
00
相似问题