4 ms·
This is exciting, and at the same time I wish this came out before writing thousands of lines of code on my React app... I can see the possibilities this bring
by aurbano 8y ago
This is exciting, and at the same time I wish this came out before writing thousands of lines of code on my React app...
I can see the possibilities this brings, and they're much better than the mess of props, local state, redux, and HoCs that we have. But the refactoring needed is just insane.
Has anyone gone through something like this and has any tips?
- Vinnl 8y agoThe primary tip is: don't refactor. It's unlikely to solve any problems if you already have working code in which you've already dealt with all the hassles of HoCs and such. You can just start using it in new code to avoid having to deal with it for that.
- aurbano 8y agoI follow this sometimes but having a wide range of patterns in the same project feels so dirty in a way... Although it makes sense, refactor only when you need to.
- Vinnl 8y agoI understand. I feel like the consideration to make is: will the benefits of hooks outweigh the benefits of mixing different patterns? If your estimate is that it won't, I'd stick to the current patterns for a while, rather than rewriting them now - because I'm quite sure the benefits of hooks aren't going to be worth the rewrite.
- WorldMaker 8y agoI feel like most production React I've seen already has a mixture of components written as classes versus ones written as functions versus functions and classes written to be HOCs. Adding Hooks in most codebases won't make most of them feel anymore "mixed" than they already were.
- cupofjoakim 8y agoDo it piece by piece. There's no need to do it all at once, so start incorporating it where it makes sense when opportunity shows itself. By doing a massive rewrite you're just inviting badly structured code.
- danabramov 8y agoWe’re not refactoring anything at FB and don’t recommend you to either! We mostly use Hooks in new code.
- aurbano 8y agoSounds good! Absolutely didn’t expect getting a reply from you on this :) I’ll use them in a couple new features and see how nice and tidy I can make things look, then think about how we’ll continue going forward. Still have a bunch of componentWillReceiveProps that need attention as well...!
- tanilama 8y agoWhy refactoring? It might be marginally better, but it doesnt mean what has been written in the past is wrong. Plus unless you have very robust test coverage, refractoring at this scale is going to introduce more bugs than the marginal benefits it will bring.