Why re-render without changing props or state?
P粉786800174
P粉786800174 2023-08-13 11:04:44
0
1
404
<p>We have a very simple application that just contains a <code>useEffect</code>, which contains a <code>console.log("first")</code>. The problem is, I want <code>console.log("first")</code> to only print once when executed, but I don't know why the re-rendering happens, and it prints twice. Please guide me, thank you. </p> <pre class="brush:php;toolbar:false;">export default function App() { useEffect(() => { console.log("first"); }, []); return ( <div className="App"> <h1>Hello CodeSandbox</h1> <h2>Start editing to see some magic happen!</h2> </div> ); }</pre> <p>https://codesandbox.io/s/silly-kilby-yn38cj?file=/src/App.tsx</p>
P粉786800174
P粉786800174

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!