3 ms·
I don't get the thing about ReactJS boilerplate where he says "Moving from React to Vue seems like a breath of fresh air. No more bind(this) or setState() every
by andrewstuart 8y ago
I don't get the thing about ReactJS boilerplate where he says "Moving from React to Vue seems like a breath of fresh air. No more bind(this) or setState() everywhere. Yay! "
Surely there's better ways of doing ReactJS rather than lots of setState? Of course I use setState but try to avoid it generally.
And I almost never, ever use bind() - don't es2015 fat arrows make it obsolete?
- acemarke 8y agoSort of. The nicest-looking approach is to use the Stage 3 Class Properties syntax to write class methods using arrow functions, which auto-binds them to the component instance as it's created (the equivalent of calling `.bind()` in the constructor).
- k__ 8y agoFunny thing is, React uses that API because two-way-binding is considered bad practice. But I guess old habits die hard...
- toddh 8y agoThe react tutorial uses bind all over the place. So they apparently think it's still necessary.
- NathanCH 8y agoIf you're using arrow functions for handlers I suspect your components are difficult to work with, unless they are very simple? Why not abstract logic to a function and bind it? That's totally normal for Javascript.
- eknkc 8y agoArrows create a brand new function on each render call. Say you have a pure component that you pass an onChange handler. If it’s an arrow function, the component needs to re-render as you created a new function. If it’s a pre bound function reference, the sub component will not receive any prop changes. Otherwise, yeah.