7 ms·
A Critique of React Hooks Addendum
- rdgthree 6y agoThis 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.
- deleted 6y ago[deleted]
- deleted 6y ago[deleted]
- hitekker 6y agoA clear, concise & clever blog post. Quizzing the community on its supposed expertise, is such an effective way to separate rhetoric from reality.
- wbobeirne 6y agoWhile 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.
- karatestomp 6y agoMaybe 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 other. "Oh we don't use doors on our buildings anymore, we've switched entirely over to trees". Huh? What the actual hell does that mean?
- searchableguy 6y agoThey 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 https://reactjs.org/docs/context.html
- karatestomp 6y agoAre 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.
- searchableguy 6y agoMaybe. 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 <Consumer> {({text}) => { return <div> {text} </div> }} </Consumer> You can do const [data] = useConsumer() return <div> {data.text} </div> It gets messy with a real complex application. typing on mobile is sad.
- hombre_fatal 6y agoIndenting by four spaces gives you preformatted text on HN. It's for code.
- jerrycruncher 6y ago
- ng12 6y agoI thought the quiz was really missing the point. The whole point of reactive programming is to not worry about execution order.
- stickfigure 6y agoI'm not quite sure what the point of this quiz is. I don't know the answer to those questions, and yet I seem to have no trouble building very large react applications (with hooks) anyway. I would also struggle with similar quiz based on the callbacks for class components. And those I actually had to deal with on a frustratingly regular basis! At least with hooks I can remain blissfully ignorant of what happens under the covers of useEffect(). Maybe the answers don't matter and this is a pointless exercise.
- acemarke 6y agoI'd definitely agree there's nuances about hook behavior that a lot of folks aren't familiar with. (Dan Abramov's mammoth post "A Complete Guide to `useEffect`" [0] ought to be required reading for all React devs, and a lot of the info in that post ought to be better integrated into the React docs directly.) That said: - The "effect behavior runs bottom to top" has always been true about class lifecycle methods like `componentDidMount` / `componentDidUpdate`. So, nothing new there. - Somewhat similarly, the aspect of new prop references causing some logic to run every time is not completely new, either - it's similar to how attempts to optimize rendering via use of `PureComponent`, `React.memo()`, and `shouldComponentUpdate` can "break" when the parent component passes down new callback or data object references every time. - The complaint that "there's more stuff to learn" seems superfluous. If there was never anything new to learn, that would mean that the API was completely stagnant and that nothing new could ever be introduced. Yes, the ecosystem is in a somewhat uncomfortable transition state atm given that there's two different APIs that offer equivalent functionality, but "learning more stuff raises the barrier to entry" is not a particularly meaningful argument against hooks. [0] https://overreacted.io/a-complete-guide-to-useeffect/ https://overreacted.io/a-complete-guide-to-useeffect/
- ng12 6y agoAgreed. At a certain point if experienced developers are struggling with the quiz it says a lot more about the quiz than the quiz-taker.