HackerTrans
TopNewTrendsCommentsPastAskShowJobs

cipinistor

no profile record

comments

cipinistor
·hace 7 años·discuss
When Hooks are not properly understood, blog posts like this one make hooks look bad. However, that is just an error from the author, which results into unnecessary and overly complicated "solutions".

Yes, Hooks take a bit of getting used to and until you get them they will be ... weird. I did a few mistakes trying hooks until I actually "got" them (the fact that I tried to use hooks without actually understanding them certainly didn't help). But learning to do them right was certainly not harder than learning the quirks of classes.

In the beginning I thought they complicate the code unnecessarily.

Until I realized they can just be extracted into custom hooks.

The real power of hooks, besides the fact they are declarative!, is composition and by means of composition they can be abstracted away as custom hooks.

React is all about declarative UI composition but lacked the “primitive” for having stateful logic composition in an elegant and declarative way.

Until hooks!