Live data from Hacker News

A Critique of React Hooks Addendum

dillonshook.com

11–20 of 56 posts

Re: A Critique of React Hooks Addendum

#11

Earlier quoted context omitted.

They might be using context. The problem with that though is it will cause performance issues due to unintentional rerendering. Not something to worry about for a small app. https://reactjs.org/docs/context.html

Are people just using "hooks" to mean "all new functionality in React that happens to be available to/as hooks"? To me it's like (actually very like) "oh we're doing that with methods". Uh. OK? Cool I guess? That's not informative.

Maybe. I really don't know.

There are some places where functionality is dependent on hooks.

React fast refresh won't work with class components. (useState is the hook alternative to class style state management and fast refresh is fancy hot reloading but with persisted state and only reloading modified modules/components).

There are few escape hatches only built as hooks mostly for improving performance issues which weren't previously available. But most of the hooks are basically reimplementation of features from class style components.

There are differences in how hooks work though. Hooks are executed as they are laid out.

Previous life cycle methods were dumped into a single useEffect hook.

It's easy to change hooks and introduce separation in how you build your logic is what I assume they might be referring to.

Instead of

{({text}) => {

  return  {text} 
}}

You can do

const [data] = useConsumer()

return {data.text}

It gets messy with a real complex application.

typing on mobile is sad.

Re: A Critique of React Hooks Addendum

#12

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…

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/anchoring of state and callbacks trivial compared to other mechanisms, providing similar peace of mind that you're not boxing yourself into an inextensible component tree. (This is regardless of context; passing down props isn't a large pain point, and is often misguided to try to solve because it leads to importable components and hidden contracts.)

Render props and HoCs solve similar problems for composition/reuse of functionality (these are all mixins at heart), but the hoistability of hooks is really the distinguishing mark in my experience.

Re: A Critique of React Hooks Addendum

#13
post #3

A clear, concise & clever blog post. Quizzing the community on its supposed expertise, is such an effective way to separate rhetoric from reality.

While I like the post and associated quiz, I feel like execution order is not the most important thing to understand with hooks, but it's the main theme of the quiz. If you're designing your components in an effective way, execution order shouldn't _really_ come into play. It typically only comes to bite you if you're manipulating some global state outside of React, or doing some direct DOM manipulation.

Questions 3 and 4 about anonymous objects and useRef are definitely the kind of knowledge that someone who aims to understand React and Hooks should focus on, though.

Re: A Critique of React Hooks Addendum

#14

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…

Hi, I"m a Redux maintainer.

Context and hooks don't "replace Redux", but they do overlap with some of the scenarios and use cases that previously led people to choose Redux.

Please see my post "Redux - Not Dead Yet!" [0] for information on how Redux compares to tools like React context + hooks and GraphQL, as well as situations in which it makes sense to use Redux.

I'd also suggest reading my post "React, Redux, and Context Behavior" [1] and watching my Reactathon 2019 talk on "The State of Redux" [2] for additional information on these topics.

As you noted, "hooks" and "Redux" are not exclusive. We released our React-Redux hooks API [3] last year, and it's been pretty enthusiastically adopted. We're now updating our docs to show using the hooks API as the default instead of `connect`.

[0] https://blog.isquaredsoftware.com/2018/03/redux-not-dead-yet...

[1] https://blog.isquaredsoftware.com/2020/01/blogged-answers-re...

[2] https://blog.isquaredsoftware.com/2019/03/presentation-state...

[3] https://react-redux.js.org/api/hooks

Re: A Critique of React Hooks Addendum

#15

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…

[deleted]

Re: A Critique of React Hooks Addendum

#16

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'd guess comments like this come from people thinking the primary complexity of Redux is the data store, rather than the "all changes to your state are represented as plain objects". The Redux FAQ goes into this: https://redux.js.org/faq/general#when-should-i-use-redux Can't blame them missing the forest for the trees when you spend all your time writing the reducers and connectors vs the actions themselves.

Note that our new official Redux Toolkit package [0] simplifies most Redux use cases and logic, including eliminating the need to write action creators and action types by hand and allowing "mutating" immutable update logic in reducers. The React-Redux hooks API [1] is also generally simpler to use than `connect`. We're now recommending that people use RTK as the default approach for Redux apps [2], and I'm working on a new set of tutorials that will teach RTK and React-Redux hooks as the standard approach [3].

[0] https://redux-toolkit.js.org

[1] https://react-redux.js.org/api/hooks

[2] https://redux.js.org/style-guide/style-guide#use-redux-toolk...

[3] https://github.com/reduxjs/redux/pull/3740

Re: A Critique of React Hooks Addendum

#17

Earlier quoted context omitted.

They might be using context. The problem with that though is it will cause performance issues due to unintentional rerendering. Not something to worry about for a small app. https://reactjs.org/docs/context.html

Are people just using "hooks" to mean "all new functionality in React that happens to be available to/as hooks"? To me it's like (actually very like) "oh we're doing that with methods". Uh. OK? Cool I guess? That's not informative.

You're probably not far off. For the Redux case, that statement almost certainly means using at least one top-level Context Provider along with `useContext` in consuming components to replace or avoid the use of a Redux store and `connect`.

Re: A Critique of React Hooks Addendum

#18
post #12

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…

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.

Re: A Critique of React Hooks Addendum

#19
This was a great follow up. I completely agreed with the first post, and I couldn't help but think those critiquing it didn't quite understand what they were critiquing. It's rare that you're able to actually definitively prove that out, but these results are about as conclusive as it gets.

Re: A Critique of React Hooks Addendum

#20

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…

Normally they mean they are using React Context, useReducer and React.memo/useMemo.

Most of the people saying that are using that are suggesting it lowers the code complexity as in the code is easier to understand or follow.

They probably will also split up the application state in multiple React context, one for auth, one for settings, things that aren't depending on one another.

Especially, when you are application doesn't have to manage that much state yet. I think it's a reasonable approach to get started with it. You can always switch to something like Mobx state trees or Redux at later time.

Post reply on HN