5 ms·
I like function components too, but I've seen some interesting arguments against using them: https://medium.freecodecamp.org/7-reasons-to-outlaw-reacts-functio
by peterjmag 8y ago
I like function components too, but I've seen some interesting arguments against using them:
https://medium.freecodecamp.org/7-reasons-to-outlaw-reacts-functional-components-ff5b5ae09b7c https://medium.freecodecamp.org/7-reasons-to-outlaw-reacts-f...
And I wish I had a reference for this, but I seem to remember reading that any future performance optimizations that could be applied to function components could probably also be applied to class components (at least ones that contain only a render() function and nothing else).
In any case, I'm hoping that React eventually gets to a point where developers don't have to make a choice between class and function components, and the compiler or the runtime makes that decision for us on a per-component basis.
EDIT: As an example, here's a Babel plugin that takes care of the conversion for you at compile time: https://github.com/remcohaszing/babel-plugin-transform-react-class-to-function https://github.com/remcohaszing/babel-plugin-transform-react.... Not sure what its heuristics are for determining what should and shouldn't be converted though, if any.