9 ms·
To further restrict these component methods from having side effects, could React call these methods using a Proxy or eval() context that blocks these methods f
by cpeterso 5y ago
To further restrict these component methods from having side effects, could React call these methods using a Proxy or eval() context that blocks these methods from reading or setting variables in the global context?
- brundolf 5y agoWould be extremely hard, especially given we're not just talking about core APIs like fetch: React code uses closures like crazy, and you couldn't wrap and probably couldn't eval-shadow every single object in scope that might get mutated You might be able to catch some common cases, but that might give a false sense of security Enforcing against side-effects in JavaScript is pretty much a lost cause. Even merely accessing a property can cause side-effects, thanks to getters and proxies