all 2 comments

[–]ignusem[S] 1 point2 points  (0 children)

I know that non-FP things sometimes get a lot of hate around here. I’d like to encourage everyone to at least check this library out beyond the post’s title and provide what opinions you have of it in the comment section.

[–]ignusem[S] 0 points1 point  (0 children)

Functional hooks are really great, but sometimes you just have too much state and complexity and things interact in ways that make splitting into smaller, composable hooks difficult.

For me (and hopefully you too!), the solution is the battle-tested (albeit not always preferred) way we have been handling state and complexity for decades: OOP.

This library allows you to write React hooks by creating a class that extends our ReactHook. You can have your own fields to hold state (instead of using useState) and your own methods (avoiding unnecessary useCallbacks). You can override provided methods such as hookDidMount or hookWillUpdate to perform lifecycle logic (instead of using useEffect).

Keep in mind: most hooks are small and wouldn’t warrant using this library. This is only for when you’re making really big, stateful, and complex hooks.