【发布时间】:2021-01-25 13:48:23
【问题描述】:
这是我打开页面时重新渲染两次的简单组件:
import React, {useState} from 'react'
export default function TestComponent() {
console.log("test component rendered")
const [count, setCount] = useState(0)
return (
<div>
TEST COMPONENT
</div>
)
}
这发生在 v16.13.1 中,但在 v.17.0.1 中可以正常工作。有没有办法在 v16.x 中修复它?
【问题讨论】:
-
你在使用 React 的严格模式吗?
-
React.memo() 没有帮助
-
...好的。你在用strict mode吗?
-
是的。我愿意..
标签: reactjs react-hooks