Live data from Hacker News

A Critique of React Hooks Addendum

dillonshook.com

21–30 of 56 posts

Re: A Critique of React Hooks Addendum

#21
post #12

Earlier quoted context omitted.

One of the problems Redux is used to solve (as a global store) is peace of mind that you won't need to refactor large swathes of component trees to reparent state and callbacks that need to be shared or persisted across different subtrees as new business requirements arise. Hooks (especially custom hooks, which are just a composition of other hooks packaged together as a single function) make the reparenting/hoisting…

Replacing redux with hooks that return local state can be a road to hell, as calling the hook somewhere down the tree will duplicate the state and there is no good way to prevent developers doing that.

IMO that's not much different than introducing a new variable in your global state to represent the same thing because you didn't realize there was already one there.

If you have a team you need discipline, code reviews, and leadership. No state solution is going to solve this for you.

Re: A Critique of React Hooks Addendum

#22

Maybe a good place to ask this: I've been hearing a lot of "oh we don't use Redux, we use hooks" lately, as if this obviously makes sense. Am I missing something? To me this seems like "oh we don't use Redux, we use arrays". I'm gonna need quite a few more details before I can make any sense of a statement like that. Like... what? How... how does that explain what you're doing? One of these things is not like the oth…

The implication behind “we don’t use Redux, we use hooks” is that they’re using React’s Context API directly as a “store”. A component at the top level has some state, probably using the useReducer hook, that state is passed down using a Context Provider, and child components can access the data with useContext.

You can DIY a Redux imitation with hooks pretty easily but making it as performant as Redux is harder.

Re: A Critique of React Hooks Addendum

#23

Maybe a good place to ask this: I've been hearing a lot of "oh we don't use Redux, we use hooks" lately, as if this obviously makes sense. Am I missing something? To me this seems like "oh we don't use Redux, we use arrays". I'm gonna need quite a few more details before I can make any sense of a statement like that. Like... what? How... how does that explain what you're doing? One of these things is not like the oth…

It seems like the react community just hops on whatever the latest & hottest blog post of the month is about.

Whenever I ask react devs(in real life) why they use feature X or library Y they usually just regurgitate the latest talking points they saw on reddit as if react is some sort of political party. Follow up questions never go anywhere that isn't covered by the latest group think.

Re: A Critique of React Hooks Addendum

#24

Maybe a good place to ask this: I've been hearing a lot of "oh we don't use Redux, we use hooks" lately, as if this obviously makes sense. Am I missing something? To me this seems like "oh we don't use Redux, we use arrays". I'm gonna need quite a few more details before I can make any sense of a statement like that. Like... what? How... how does that explain what you're doing? One of these things is not like the oth…

I can give my take on this.

Until hooks I used redux in every app because it was the default way to manage state. Now I use hooks, I have more tools to help me manage state (and also load things via useEffect), I find I simply don't need redux anymore. The only compelling reason for me to pull in redux now would be if I wanted a centralised cache, but the kind of line of business apps I mostly work on lately just don't need to cache things like that, so each route/page just reloads the data from the server.

Re: A Critique of React Hooks Addendum

#25
post #23

Maybe a good place to ask this: I've been hearing a lot of "oh we don't use Redux, we use hooks" lately, as if this obviously makes sense. Am I missing something? To me this seems like "oh we don't use Redux, we use arrays". I'm gonna need quite a few more details before I can make any sense of a statement like that. Like... what? How... how does that explain what you're doing? One of these things is not like the oth…

It seems like the react community just hops on whatever the latest & hottest blog post of the month is about. Whenever I ask react devs(in real life) why they use feature X or library Y they usually just regurgitate the latest talking points they saw on reddit as if react is some sort of political party. Follow up questions never go anywhere that isn't covered by the latest group think.

Personally, hooks have vastly simplified my code bases by giving me an out-of-the-box toolset for managing and fetching state. Not using redux means tons less boilerplate and actually means each "page" of my SPA's are totally decoupled from each other. (You can do this with redux by giving each page its own store but you need to be disciplined and refactoring can be tricky).

Re: A Critique of React Hooks Addendum

#26
post #25
post #23

Earlier quoted context omitted.

It seems like the react community just hops on whatever the latest & hottest blog post of the month is about. Whenever I ask react devs(in real life) why they use feature X or library Y they usually just regurgitate the latest talking points they saw on reddit as if react is some sort of political party. Follow up questions never go anywhere that isn't covered by the latest group think.

Personally, hooks have vastly simplified my code bases by giving me an out-of-the-box toolset for managing and fetching state. Not using redux means tons less boilerplate and actually means each "page" of my SPA's are totally decoupled from each other. (You can do this with redux by giving each page its own store but you need to be disciplined and refactoring can be tricky).

Why was redux chosen in the first place if it had tons of boilerplate, etc?

Re: A Critique of React Hooks Addendum

#27
post #23

Maybe a good place to ask this: I've been hearing a lot of "oh we don't use Redux, we use hooks" lately, as if this obviously makes sense. Am I missing something? To me this seems like "oh we don't use Redux, we use arrays". I'm gonna need quite a few more details before I can make any sense of a statement like that. Like... what? How... how does that explain what you're doing? One of these things is not like the oth…

It seems like the react community just hops on whatever the latest & hottest blog post of the month is about. Whenever I ask react devs(in real life) why they use feature X or library Y they usually just regurgitate the latest talking points they saw on reddit as if react is some sort of political party. Follow up questions never go anywhere that isn't covered by the latest group think.

I don't think that you'd be able to get a very clear answer from your average frontend developer on why their non-React framework of choice uses the state management pattern that it does. For that matter, most DBA's wouldn't be able to answer detailed questions about their chosen database's query optimizer, and most ML researchers wouldn't be able to answer questions about Numpy's choice of linear algebra algorithms. Sometimes people just need to do their jobs without understanding every nuanced choice all the way down the stack. Luckily, software libraries let us do that.

Re: A Critique of React Hooks Addendum

#28
post #27
post #23

Earlier quoted context omitted.

It seems like the react community just hops on whatever the latest & hottest blog post of the month is about. Whenever I ask react devs(in real life) why they use feature X or library Y they usually just regurgitate the latest talking points they saw on reddit as if react is some sort of political party. Follow up questions never go anywhere that isn't covered by the latest group think.

I don't think that you'd be able to get a very clear answer from your average frontend developer on why their non-React framework of choice uses the state management pattern that it does. For that matter, most DBA's wouldn't be able to answer detailed questions about their chosen database's query optimizer, and most ML researchers wouldn't be able to answer questions about Numpy's choice of linear algebra algorithms.…

I feel going out of one's way to use a 3rd party library like Redux with React is a bit different than a database's internal query optimizer.

Quite frankly the fact so many developers are replacing Redux with hooks is proof it was never the right choice for their project in the first place.

Re: A Critique of React Hooks Addendum

#29

Maybe a good place to ask this: I've been hearing a lot of "oh we don't use Redux, we use hooks" lately, as if this obviously makes sense. Am I missing something? To me this seems like "oh we don't use Redux, we use arrays". I'm gonna need quite a few more details before I can make any sense of a statement like that. Like... what? How... how does that explain what you're doing? One of these things is not like the oth…

If you ask a random sampling of Redux users why they're using it, you'll get tons of different answers. Some people use it as a caching layer. Other people use it because their SSR solution requires it. Other people use it because they like the action-command pattern. Other people just use it because they see it as the "M in MVC" and consider it mandatory in their projects. Other people just use it because it's the default. Some people use it for more than one reason.

If something else comes along and fits one of those niches, it's no wonder people will get interested in it. It was the same with Apollo. A lot of projects replaced Redux with it.

And to answer your question: some people are moving to hooks because of useReducer. Others because of useContext. Others because they can create custom Hooks. Some because of third-party hooks. Others for a mix of those.

Re: A Critique of React Hooks Addendum

#30

Earlier quoted context omitted.

Replacing redux with hooks that return local state can be a road to hell, as calling the hook somewhere down the tree will duplicate the state and there is no good way to prevent developers doing that.

IMO that's not much different than introducing a new variable in your global state to represent the same thing because you didn't realize there was already one there. If you have a team you need discipline, code reviews, and leadership. No state solution is going to solve this for you.

I always try to tell folks that frameworks won't save them from themselves.
Post reply on HN