import React, { useState, useEffect } from "react";
export default function Example() {
const [count, setCount] = useState(0);
const [tmp, setTmp] = useState(0);
useEffect(() => {
document.title = `You clicked ${count} times`;
setTmp(count);
console.log(tmp);
});
return (
<div>
<p>
You clicked {count} times and temp is {tmp}
</p>
<button onClick={() => setCount(count + 1)}>Click me</button>
</div>
);
}
After reading this I expected this to cause infinite re-render because a state tmp
is getting changed inside the useEffect but it didn't, can someone please help what might be the cause?