window.data = {}
useEffect(() => {
// do something
}, [window.data])
Does the above code makes sense?
since window.data is global, it won't be different on renders, and the effect won't execute?
No, that won't work. Effect could only be triggered when component is rerendered and dependencies change. Changing global variables won't cause a rerender, so the effect won't run.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With