3 ms·
React hooks are just a fancy (perhaps unnecessary) way of getting people to embrace closures, which help you avoid other common footguns when dealing with tempo
by anonytrary 8y ago
React hooks are just a fancy (perhaps unnecessary) way of getting people to embrace closures, which help you avoid other common footguns when dealing with temporal data. If you understand closures and you know how to use them to "remember environments", then React hooks are little more than tools for concision.
- boomlinde 8y agoOther than e.g. useEffect returning a function that closes around something within, I don't see what hooks have to do with closures.
- anonytrary 8y agoYou don't need hooks to do any of this, but hooks have everything to do with closures. Hooks are created every single render, unconditionally, guaranteeing that each hook is one-to-one with the render environment that created it. The point of using hooks is that you are always referencing the props and state at the time of creating the hook and not at the time of running the hook. In this way, hooks become part of your rendered output.
- boomlinde 8y agoI know how hooks work, but what you describe has nothing to do with closures.