DEV Community

Discussion on: MoonZoon Dev News (3): Signals, React-like Hooks, Optimizations

Collapse
 
martinkavik profile image
Martin Kavík

A good note from Pauan:

--
btw, another issue you didn't mention in your article... events are often really problematic in VDOM
because in React, if you do something like this...
<Foo onclick={(e) => { ... }} />
every time render is called, it will create a fresh new closure
that's already not great, but it gets even worse
because now React has to unbind the old onclick handler and add the new onclick handler
and it has to do this on every single render
which is why it's common practice to do things like this.onclick = this.onclick.bind(this);
so that way you can do <Foo onclick={this.onclick} />
so that way the closure doesn't change, so React doesn't have to update it