Live data from Hacker News

Kind of annoyed at React

blog.cassidoo.co

31–40 of 135 posts

Re: Kind of annoyed at React

#31
post #18

> it’s not clear/an easily understandable mental model for most people That's already the case, thanks to hooks. Hooks are weird, and should not be taught to junior programmers because it will confuse them for the rest of their careers. Hooks are weird because it doesn't align with functional programming paradigm or with OOP paradigm... it is a new paradigm and it is like nothing else. More on that: https://medium.co…

I'll never understand the "hooks are bad" people. I don't find useEffect confusing, creating custom hooks is a breeze, life is so much better than old class components. When I read complaints about hooks I'm either missing something fundamental about why they're bad, or the people complaining are missing it.

From my experience (picked up react when it came out) hooks are not objectively better than class components in a standard web app. In the more reactive scenarios hooks are great, and your app is already complex and in its own world of mental models.

Hooks enable complex patterns too easily and I think this causes a lot of breakdown in what would otherwise be simple applications.

Re: Kind of annoyed at React

#32
post #5

Earlier quoted context omitted.

For those that are not following very closely, what came after the “hooks” that took it too far?

Server components, which are in Next.js (using React's canary branch). Server components are not yet in official (i.e. non-canary) React, and the React team supports this move (as do I). I just wish that the tool that was so helpful with the "other" (100% client-side) React, "Create React App", was better supported these days.

Create React App is in a strange, pseudo-death state.

- It is not listed as an option for starting a new project in the React docs[0].

- The last release was April 12, 2022.

- The last time I created a new project with CRA, it printed a console log that claimed CRA was deprecated. However, the message seemed to originate from a dependency rather than CRA itself.

All this was enough to convince me to move to Next.js for future projects; though I find Next.js overcomplicated and full of things I will never use.

0 - https://react.dev/learn/start-a-new-react-project

Re: Kind of annoyed at React

#33
post #15

Earlier quoted context omitted.

I totally disagree. React hooks are one the best things ever invented.

> one the best things ever invented Fire? The wheel? Penicillin? Maybe it's just because I'm getting older, but I'm increasingly annoyed when people use these sorts of over-the-top hyperboles.

One of the best things ever invented in component based frontend frameworks. It makes purely functional frameworks like modern react much easier to deal with.

Off course it's a violation of some theoretical principals. So what?

What I don't get: people complain about not being able to handle all the useEffects, but they probably shouldn't be there in the first place. In my experience most ambiguous use effects can be easily removed. They are rarely needed for anything but library code or interaction with browser APIs.

Re: Kind of annoyed at React

#34
Nextjs is pushing for the server components and I don't really blame them for doing so. Netlify is trying to back anything that's not nextjs. If anything I'm kind of surprised that big cloud players are completely ignoring this market right now.

Re: Kind of annoyed at React

#35
post #18

Earlier quoted context omitted.

I'll never understand the "hooks are bad" people. I don't find useEffect confusing, creating custom hooks is a breeze, life is so much better than old class components. When I read complaints about hooks I'm either missing something fundamental about why they're bad, or the people complaining are missing it.

"useEffect" itself is not what is confusing. What's confusing is when you have many dozens of components with effects all loading state asynchronously. Some of them might even be executing callbacks passed as props from parent components. Oh, and then those effects sometimes re-execute when the effects of parent components complete and pass down updated props! It actually reminds me of programming VHDL.

And that's why using effects for such tasks is a huge anti pattern.

https://react.dev/learn/you-might-not-need-an-effect

Re: Kind of annoyed at React

#36
post #18

Earlier quoted context omitted.

I'll never understand the "hooks are bad" people. I don't find useEffect confusing, creating custom hooks is a breeze, life is so much better than old class components. When I read complaints about hooks I'm either missing something fundamental about why they're bad, or the people complaining are missing it.

Some people find the mental model to be very confusing. I've been writing hooks for years so intuitively, the behavior has sunk in. But I still admit that it's mind bending to try and understand how it actually works. The original commenter is absolutely correct that it diverges from both functional and OOP, and while that's not necessarily a bad thing, it's reasonable for people to consider it a net negative.

Whats the beat resource for the mental model?

Re: Kind of annoyed at React

#37
post #35

Earlier quoted context omitted.

"useEffect" itself is not what is confusing. What's confusing is when you have many dozens of components with effects all loading state asynchronously. Some of them might even be executing callbacks passed as props from parent components. Oh, and then those effects sometimes re-execute when the effects of parent components complete and pass down updated props! It actually reminds me of programming VHDL.

And that's why using effects for such tasks is a huge anti pattern. https://react.dev/learn/you-might-not-need-an-effect

The problem is you literally need to use effects to make api requests or access browser apis. You can't get away from it. Maybe you can try and tame the complexity by centralizing this logic as a small team but if the team gets big enough it's fruitless.

Re: Kind of annoyed at React

#38
post #29
post #22

Earlier quoted context omitted.

I agree. Up until Hooks, you could make your own toy React pretty easily if you wanted to - creating a basic, unoptimised version took a few hours. That made the whole system pretty understandable, especially for junior developers - obviously, you'd always pick the battle-hardened, optimised real React for anything serious. Hooks fundamentally altered the contract about the API that React provided, and suddenly magic…

But all the lifecycle methods were magic that needed to be understood... hooks just let you co-locate related logic in one place instead of scattered across 3 or 4 lifecycle methods.

I disagree that they were magic - you could build a test renderer for yourself and see pretty easily how they'd work. The system as a whole was understandable, and it fit into an existing mental model: you implement this interface, and React will call your methods. The specifics of how and when it did were part of the system on the other side of the interface.

Hooks on the other hand are functions that you call, which implicitly rely on a magic global state and context, and you cannot use them like other JS functions. You can't conditionally call them or change the order of them, because they contain a unique ID based on call order, which is Spooky (and is why React has to build its own ESLint rules to make sure you don't mess it up!).

Don't get me wrong - I do think the ergonomics of hooks are a lot better, but I think at least part of that is due to it being a newer iteration of the API.

Re: Kind of annoyed at React

#39

React is fundamentally bad technology. I know there are historical reasons for the virtual dom but the reasons that justified it don't exist anymore. If you want to do anything interesting with react that involves interacting directly with browser APIs you need to deal with these absurd use effect hoops to initiate state with references to dom nodes. I've worked on 4 large react code bases and they always devolve int…

> they always devolve into these blobs of non-deterministic async state with unpredictable performance Exact same experience here. I've been banging this drum for years. When hooks came around I thought they might make it better, but alas, we are still in a downwards spiral. Building web apps is 10x more complicated today than it was ten years ago, with nothing to show for it. I'm happy to see some known voices in th…

Building web apps with React is just much faster than doing it without, even when using Angular complex apps will always be complex.

You can’t have an easy solution when you have tons of interaction and state.

Re: Kind of annoyed at React

#40
post #35

Earlier quoted context omitted.

And that's why using effects for such tasks is a huge anti pattern. https://react.dev/learn/you-might-not-need-an-effect

The problem is you literally need to use effects to make api requests or access browser apis. You can't get away from it. Maybe you can try and tame the complexity by centralizing this logic as a small team but if the team gets big enough it's fruitless.

You're right, but I haven't touched a React project in ages that wasn't using a fetch library of some kind that give you hooks.

Cause you're inevitably gonna want to track loading state, error state, refetch on error, revalidate etc etc.

swr or tanstack-query are great and remove the need for useEffects for API requests. For sure they come with their own overhead, but there isn't getting away from the complexity of handling API requests and all the possible paths that can happen.

Post reply on HN