5 ms·
I've never really understood the hooks are complicated line. Maybe it's the understanding that they integrate with React's event system (which I think is power
by bern4444 5y ago
I've never really understood the hooks are complicated line.
Maybe it's the understanding that they integrate with React's event system (which I think is powered by something like rxjs/observables), but hooks make the most sense once you start implementing custom hooks which are incredibly easy to write and reuse.
Need a hook for undoable (and re-doable) state? It can be implemented in ~30 lines and then used anywhere in your application.
Need a hook to manage data from an API across your application, a custom hook makes this trivial especially if you need to connect it with your global state management (like redux/context/etc).
JSX is nothing special and it's possible (and trivial) to set up your component files to use a .js extension.
The only thing JSX does is let you write components with an HTML like syntax instead of with a bunch of function calls. I find this extremely ergonomic.
Bad React is when the two ideas - view and component logic - are mixed too much. That's the point at which components need to be broken down further to avoid bloat or a custom hook is needed to handle data.
- toastercat 5y agoI feel like you're speaking completely past me, because I never said using hooks were complicated. On the surface, they simplify quite a whole lot to the point where complete beginners to JavaScript can grasp them and be productive quickly.