Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> I recently had to fix a few bugs because some devs forgot, or simply didn't know, that lifecycles still exist.

And then it just stays fixed. You don't have to split up the logic across different lifecycle methods and remember to keep them in sync. They're consolidated into functions that can be trivially pulled out into their own hooks and reused.

React is definitely a more low-level framework that requires you to have some familiarity with how the scheduler works, and could benefit from a couple more built-in hooks. But the benefits are undeniable, they make writing and refactoring complex applications an absolute breeze. The fact that you can factor out some state-related behavior into a hook and trivially reuse it is incredible.

For example, take state. With hooks, you use useState. A very common pattern is to need to persist it in the URL to enable deep linking. You can literally just replace your useState call with useQueryParam from the use-query-params library [1] and have your component function identically. You just can't do that with class-based components.

[1] https://www.npmjs.com/package/use-query-params



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: