【发布时间】:2020-08-16 08:32:41
【问题描述】:
为什么我的组件会渲染两次?
export default function App() {
console.log("asd");
const [count, setCount] = useState(0);
return (
<div>
<Title count={count} />
<button
onClick={() => {
setCount(count + 1);
}}
/>
</div>
);
}
//console= "asd" "asd"
它的渲染两次,但如果我删除 useState 它不会发生
【问题讨论】:
-
因为应用程序被包裹在 React.StrictMode 中并且你在开发模式下运行。
-
这能回答你的问题吗? React Hooks render twice
标签: reactjs react-hooks render