export default function Example() {
useEffect(()=>{
console.log('DOM has not rendered anything yet')
});
return (
<div>
Hello
</div>
);
}
What am I getting with the above code is the console message first and then Hello appears on my page. However, by debugging the code I can see return precedes useEffect. Why then Hello is not visible when useEffect runs for the first time?
Moreover, if using the code from https://reactjs.org/docs/hooks-effect.html#example-using-hooks:
function Example() {
const [count, setCount] = useState(0);
useEffect(() => {
document.title = `You clicked ${count} times`;
});
return (
<div>
<p>You clicked {count} times</p>
<button onClick={() => setCount(count + 1)}>
Click me
</button>
</div>
);
}
seeing that when callback of useEffect is being executed for the first time, only the button is visible not You clicked 0 times.
