4 ms·
I honestly don't know how hooks work that well but I find them easier in general to make quick reusable stuff or just plug things in without having to worry abo
by omniscient_oce 6y ago
I honestly don't know how hooks work that well but I find them easier in general to make quick reusable stuff or just plug things in without having to worry about layers deep of Higher order components. There used to be class = logic , pure function = takes data and outputs jsx. But now functional components manage their own state and somehow trigger rerenders of themselves (how do they do this btw?). So they don't really seem to be 'functional' in the functional programming sense, but more the 'we use the function syntax of JS' sense. I don't know haha.
- flanbiscuit 6y ago> (how do they do this btw?) these links might help explain https://medium.com/@ryardley/react-hooks-not-magic-just-arrays-cd4f1857236e https://medium.com/@ryardley/react-hooks-not-magic-just-arra... https://dev.to/kayis/react-hooks-demystified-2af6 https://dev.to/kayis/react-hooks-demystified-2af6
- kybernetikos 6y ago> don't really seem to be 'functional' in the functional programming sense, but more the 'we use the function syntax of JS' sense That's right. A true function has referential transparency. I get that hooks have ergonomic benefits in some situations, but I wish people wouldn't call them "functional".
- s_y_n_t_a_x 6y agoWho is saying that, the point of hooks is composability.
- rhinoceraptor 6y agoI don't think FP purity is the point of hooks, the advantage is the ability to compose them, more easily than HOCs.
- karatestomp 6y agoHow objects work: there's a lookup table for methods and properties associated with your instance to find them by name (or call signature, or whatever). How hooks work: there's a lookup array associated with your instance (yes, an instance of an object—read the code if you're skeptical, and besides functions are objects in JS anyway so even if I'm wrong, which I'm not, I'm technically right) to find properties and methods by reference order(!?!) Hooks are just a crippled implementation of objects with weird syntax. In a language that already has non-crippled ones built in with less-weird syntax.
- golergka 6y agoSo, closures are indeed poor man's objects.
- karatestomp 6y agoIt's storing all the hooked-in functions (methods) and variables (properties) outside the function and associating them with the relevant React view object instance at run-time, which is effectively the hooks' "this". Unless the code's change substantially and in very fundamental ways since it was introduced. It doesn't bring to mind closures, at least as I read it. It very much brings to mind object/class-system implementations.