I came across this when I was experimenting with react components. I have a component:
window.renderCount=1;
export function Soundscapes() {
const soundscape = useSelector((s) => s.tasks.soundscape);
const dispatch = useDispatch();
const [soundscapeAudioElement, setSoundscapeAudioElement] = useState(undefined);
useEffect(()=>{
console.log('state just changed to: ', soundscapeAudioElement )
},[soundscapeAudioElement])
console.log(window.renderCount);
window.renderCount=window.renderCount+1;
return (<SomeJSXUnrelatedToQuestion/>)
}
In the console, I noticed that the logs are 1,3,5,7,9
on subsequent re-rendering. I expected it to print renderCount
everytime it is incremented by 1 on the screen like 1,2,3,4,5
, each time the component got rendered to screen. But it seems to be incrementing it, but not printing it to console everytime.
Am I missing something here?