Hooks are the worst thing to ever happen to React. They're so easy to get starte... (2024)


Hooks are the worst thing to ever happen to React. They're so easy to get started with but every codebase I've seen adopt them has turned into complete untestable spaghetti.

Mixing stateful effectful code inside what would otherwise be a pure declarative render function leads to so much complexity in an attempt to bridge the two paradigms. Junior engineers are also constantly tripped up by the subtleties of `useEffect` and `useState`.

Furthermore I think attempting to "encapsulate" side effects is a bad approach to writing testable programs. Most React components that use hooks end up having several chains of promises inside them but no way to await the final promise meaning tests have to be full of

 await wait(0) await wait(0) await wait(0)

God forbid someone comes along and tries to be clever and replaces it with

 await wait(3)

which now makes the test non-deterministic.

Cycle.js is the only framework that seems to get this right by acknowledging that a component doesn't just output JSX, but actually outputs JSX, HTTP Requests, etc.

Look, I get that Redux was a pain in the ass with all the boilerplate, but how did we throw the baby (unidirectional data flow) out with the bathwater. I no longer advertise that I know frontend development because the entire react community seems to have lost its mind.

Hooks are the worst thing to ever happen to React. They're so easy to get starte... (1)

warent on Dec 17, 2020 | next [–]


Is there anybody that develops on the frontend professionally fulltime and makes these kinds of complaints?

It seems like these are always drawn up by backend developers who lob fistfuls of aggression-poop over the fence for reasons beyond my fathoming, or junior developers (or UI folks who occasionally use javascript) that find it easier to trash on patterns rather than learn about them.

I have used React professionally for years and get the skepticism around hooks. It seemed really stupid to me before I learned about it. Why change what wasn't broken?

Now after learning about it I'll never go back to class components if it can be avoided and happily recommend hooks to all my clients who also end up loving them.

No idea what this promise chaining thing is that you're talking about. Sounds like a bad design pattern that has nothing to do with hooks. No idea why you're suggesting Redux has anything to do with hooks. They're completely different.

This meme is dead. Only a superficial understanding of React, or ingrained bad programming pattern habits, keep this meme alive.

Hooks are the worst thing to ever happen to React. They're so easy to get starte... (2)

I've more or less driven frontend development with React at several companies over the last 4 years. While some of the complaints are exaggerated I don't think the overarching premise should be dismissed as "a meme."

> No idea what this promise chaining thing is that you're talking about.

If you have any asynchronous things going on in `useEffect`, you'll have to do something similar to that `await(0)` song and dance in tests. This specifically affects tests if you do things like update the UI by toggling loading spinners on await.

> Redux

s/Redux/higher order components. One of the motivations for hooks was that as a mechanism for logic composition, HOCs just felt awful to use. (So did render props, which everyone suddenly used for everything in a brief moment of collective insanity.)

> Only a superficial understanding of React

I think there's something in this. The fact is that good or bad, 1) hooks aren't intuitive, 2) hooks have basically doubled React's API surface area. Previously, React was so simple that a backend engineer could pick it up and get productive with it in half a week. That's much less the case these days. I've been onboarding devs to React for years, and these days there's a lot more "yeah, that's magic, you don't need to know how that works for now."

Hooks are the worst thing to ever happen to React. They're so easy to get starte... (3)

JMTQp8lwXL on Dec 17, 2020 | root | parent | next [–]


> If you have any asynchronous things going on in `useEffect`, you'll have to do something similar to that `await(0)` song and dance in tests. This specifically affects tests if you do things like update the UI by toggling loading spinners on await.

You should have a core (pure) functional component, that doesn't perform network requests, and an outer component for side effects.

Your testing for the inner component becomes trivial: Do the correct props product the correct HTML? Fairly trivial to validate. Use Enzyme, react-testing-library, etc.

The outer component, which contains side effects, can be covered through an end-to-end testing tool like Cypress.

Hooks are the worst thing to ever happen to React. They're so easy to get starte... (4)

schwartzworld on Dec 19, 2020 | root | parent | next [–]


> You should have a core (pure) functional component, that doesn't perform network requests, and an outer component for side effects

IMO, this is the biggest thing we lost with hooks. Before there were two different types of component, and you couldn't make a pure functional component stateful or effectful without completely rewriting it.

I love hooks, but I'm constantly asking in code reviews "are you sure this is where you want this state to live?".

The other big problem with hooks is that there are no safeguards (and little documentation) about using them wrong. The post you're responding to mentions using `useEffect` to toggle a loading spinner. This might make sense if the loading spinner is outside the React component tree, but if you're using useEffect to toggle some piece of React state, yer doin it wrong. Once you start slipping these kinds of hacks into a codebase, it's a slippery slope.

Hooks are the worst thing to ever happen to React. They're so easy to get starte... (5)

timhwang21 on Dec 17, 2020 | root | parent | prev | next [–]


This is true as long as you're able to strictly enforce the container-presenter pattern, which is increasingly harder to do as an application grows in complexity.

Hooks are the worst thing to ever happen to React. They're so easy to get starte... (6)

JMTQp8lwXL on Dec 18, 2020 | root | parent | next [–]


If you're using a Design System (a base level of common UI components), the separation helps enforce the design system acting as the "presenter".

Hooks are the worst thing to ever happen to React. They're so easy to get starte... (7)

BreakfastB0b on Dec 17, 2020 | root | parent | prev | next [–]


 You should have a core (pure) functional component, that doesn't perform network requests, and an outer component for side effects.

Except when you go to use that container component inside another component. Then you’re back to the same problem. Unless you’re advocating for a single container component at the top level in which case we completely agree!

Hooks are the worst thing to ever happen to React. They're so easy to get starte... (8)

dragonwriter on Dec 17, 2020 | root | parent | prev | next [–]


> Previously, React was so simple that a backend engineer could pick it up and get productive with it in half a week.

With hooks, I've literally seen almost completely novice programmers (e.g., people who’d hacked out some powershell while working desktop support previously) pick up React and be productive in a month or so, while also learning JS and Python and SQL and backend development from scratch in parallel; if backend “engineers” can't do it in half a week or so, they’re hacks.

Hooks are the worst thing to ever happen to React. They're so easy to get starte... (9)

pixelkritzel on Dec 17, 2020 | parent | prev | next [–]


Yup, I use React professionally for four years now with some really big applications (10ks LOC) and I would always opt for class components.

The hooks API not only suffer from weird wording (how is useEffect more expressive than componentDidMount) but it introduced some concepts like dependency declarations (again useEffect) and a new meta syntax.

It could have been a good development if the published preview would have been a real request for comments with the possibility of changing something. But instead it was introduced as stable in basically the same form.

Hooks are the worst thing to ever happen to React. They're so easy to get starte... (10)

WorldMaker on Dec 17, 2020 | root | parent | next [–]


> how is useEffect more expressive than componentDidMount

Well, useEffect cross-cuts way more of the component lifecycle than just componentDidMount: it also handles componentDidUpdate and componentWillUnmount, and a few other things that didn't quite get lifecycle functions before. I suppose you could call it useWhenComponentMountsUpdatesOrWillUnmount, but "effect" as in "side effect" for when the component moves through lifecycle events isn't an uncommon name for that sort of thing (even outside of React).

Hooks are the worst thing to ever happen to React. They're so easy to get starte... (11)

BreakfastB0b on Dec 17, 2020 | parent | prev | next [–]


 Is there anybody that develops on the frontend professionally fulltime and makes these kinds of complaints?

I do? These are all real problems I've encountered working on large apps at multiple organizations. React hooks are a constant source of difficult to write and non-deterministic tests. Class components also suffer from the same problems.

 Now after learning about it I'll never go back to class components.

Those aren't the only two options. What I'm advocating for is using react only for pure functional components without the use of any hooks. Hooks are completely isomorphic to class components. Instead of binding the `this` of class methods to an object as a class component would. React hooks maintain basically the same thing in the background and bind it to the values of the hooks, identifying them by call order in your component. Which is why you can't call them conditionally. They're way nicer than class lifecycle methods. Primarily because they organize code that's related together, rather than by when in the lifeCycle it is triggered.

IMO state and side effects belong outside of the render functions. Not mixed up inside them. This is exactly what redux, cycles.js, Elm, MVC, etc do.

 No idea what this promise chaining thing is that you're talking about.

You know that async await just chains promises together right? e.g.

 async () => { await foo(); await bar(); } () => foo().then(() => bar());

So any callback that makes multiple API calls will require multiple `await wait(0)` in tests to allow for the mocked API calls to resolve before the UI will be finished updating.

 No idea why you're suggesting Redux has anything to do with hooks. They're completely different.

If you can't see why Redux is related to hooks, I don't know what to say. They're both approaches to managing the impure parts of your UI. I suppose you could continue to insult my experience as a frontend engineer.

Hooks are the worst thing to ever happen to React. They're so easy to get starte... (12)

presentation on Dec 17, 2020 | parent | prev | next [–]


I agree, the main issue that I’ve had is just that its easy for (usually junior) devs to accidentally make infinite loops with interdependent state + effect hooks. But besides that I would never go back to class components.

Hooks are the worst thing to ever happen to React. They're so easy to get starte... (13)

eitland on Dec 17, 2020 | prev | next [–]


I haven't used React and React hooks as long as I have used Java and Maven, but consider this:

If many successful people voluntarily use something you cannot understand there is always the possibility that you are the one who are missing out on something.

(FWIW: I've been there myself)

Hooks are the worst thing to ever happen to React. They're so easy to get starte... (14)

BreakfastB0b on Dec 17, 2020 | parent | next [–]


I absolutely acknowledge this is a possibility, but I think I do understand why people use it. Because they're easy, hooks are just so god damn easy to use. Want some state? Just chuck in a `useState` and call it day. But the problem is, they're not simple, and that complexity will grow and grow until it makes the app unmaintainable. I've seen this happen at three different companies I've worked at.

Hooks are the worst thing to ever happen to React. They're so easy to get starte... (15)

nicoburns on Dec 17, 2020 | root | parent | next [–]


To me the main benefit isn't that they're easy, it's that they're composable. They allow you to reuse "business logic" in multiple components. If it's getting too complex then that's presumably when you ought to be creating a custom hook which wraps up some of that complexity.

Hooks are the worst thing to ever happen to React. They're so easy to get starte... (16)

valenterry on Dec 17, 2020 | root | parent | next [–]


I'm not familiar with react hooks, but when I read what you write, my immediate reaction is: we already have a way to reuse business logic. It's called functions. Define a function and use it, either a global static function or pass it down to the component if you want to mock it.

Reading the react docs, I find this part interesting:

> Hooks were designed with static typing in mind. Because they’re functions, they are easier to type correctly than patterns like higher-order components. Importantly, custom Hooks give you the power to constrain React API if you’d like to type them more strictly in some way. React gives you the primitives, but you can combine them in different ways than what we provide out of the box.

(https://reactjs.org/docs/hooks-faq.html#do-hooks-work-with-s...)

Seems to me as if hooks try to fix the lack of a good programming language. These approaches usually go wrong eventually. Maybe it's time to ditch Javascript (and even Typescript) and use a proper language (purescript maybe?) so that all these things can be done with just functions.

Hooks are the worst thing to ever happen to React. They're so easy to get starte... (17)

dragonwriter on Dec 17, 2020 | root | parent | next [–]


> I'm not familiar with react hooks, but when I read what you write, my immediate reaction is: we already have a way to reuse business logic. It's called functions.

Hooks are functions. If that wasn't obvious, it's also explicit called out as a key thing about them in the excerpt from the docs that you present and then try to make a point with that entirely ignores the content of the excerpt.

Hooks are the worst thing to ever happen to React. They're so easy to get starte... (18)

valenterry on Dec 18, 2020 | root | parent | next [–]


Apologies. When I said "functions" I meant "pure functions" in the sense that you can call them anytime and don't need to consider any special rules. An example would be `Math.pow`.

Hooks are not _just_ functions, they are special functions where that (by the documentation) should not be called inside loops, conditions, or nested functions. These are severe restrictions compared to the "normal/pure" functions that I meant.

Hooks are the worst thing to ever happen to React. They're so easy to get starte... (19)

timhwang21 on Dec 17, 2020 | root | parent | prev | next [–]


One key difference between hooks and functions is that hooks tap into some hidden global component registry (I'm being handwavey here but this is more or less what happens). This allows side effects to be persisted and tracked between function calls.

You can probably build all this infrastructure yourself without hooks and only with plain functions. It'll involve some global store and some subscription mechanism. You'll end up with something really similar to Redux.

Hooks are the worst thing to ever happen to React. They're so easy to get starte... (20)

valenterry on Dec 17, 2020 | root | parent | next [–]


> You can probably build all this infrastructure yourself without hooks and only with plain functions

It sounds to me that such a concept would be very useful in a lot of contexts, so instead of specializing it only to react hooks, it might be better to just be a standalone library. E.g., why not use the same technique in Angular?

That way, developers don't have to learn framework-specific ways of doing things again and again but can reuse their knowledge. I think the fact that everyone is building their own thing is one of the reasons why many people have this notion of "need to learn a new framework every half a year". Backend technology seems to do better here, maybe because the pace is slower?

Hooks are the worst thing to ever happen to React. They're so easy to get starte... (21)

timhwang21 on Dec 17, 2020 | root | parent | next [–]


> it might be better to just be a standalone library

See: https://github.com/reduxjs/redux, among others.

The React ecosystem did exactly this for the past few years, but evidently it was decided that a more native approach like hooks were better.

Hooks are the worst thing to ever happen to React. They're so easy to get starte... (22)

valenterry on Dec 18, 2020 | root | parent | next [–]


I know redux, but I believe that there should be an even more low level library.

Coming from the backend, I miss something like the effect system builtin in Haskell/Purescript or added as a library to languages like Scala (e.g. https://typelevel.org/cats-effect/) or Kotlin (e.g. https://arrow-kt.io/docs/effects/io/)

Hooks are the worst thing to ever happen to React. They're so easy to get starte... (23)

schwartzworld on Dec 19, 2020 | root | parent | prev | next [–]


Hooks are not an alternative to redux, although you could use then as one.

Personally, any time anybody has ever suggested using redux I have always fought it. I've never seen the news for a global state management library, since react has always had tools to manage state built in.

Hooks are the worst thing to ever happen to React. They're so easy to get starte... (24)

xwdv on Dec 17, 2020 | root | parent | prev | next [–]


One thing you are missing is a lot of organizations don’t care about UI tests. They’re brittle and the UI is always changing anyways so you get diminishing returns from writing many of them. Usually an end to end test is enough. UI logic is usually not that complicated, if it doesn’t work you will know right away. Hooks are acceptable.

Hooks are the worst thing to ever happen to React. They're so easy to get starte... (25)

sbergot on Dec 17, 2020 | parent | prev | next [–]


I have used them on a medium project. I enjoy them very much but I have seen a lot of people struggle with the "rules of hooks"*

I can see why some people prefer to use classes where the design is cleaner (even though you are more limited).

*: https://reactjs.org/docs/hooks-rules.html#:~:text=Only%20Cal....

Hooks are the worst thing to ever happen to React. They're so easy to get starte... (26)

presentation on Dec 17, 2020 | root | parent | next [–]


If you use a linter though you can just auto enforce all the rules and back to it being just fine. An extra setup step but tools like create react app bundle ESLint for you already so I don’t mind it.

Hooks are the worst thing to ever happen to React. They're so easy to get starte... (27)

dbbk on Dec 19, 2020 | parent | prev | next [–]


I actually think the problem is a lack of critical thinking. When Hooks were announced by Dan Abramov, people were hailing him as a genius etc, that this was a panacea.

Hooks are the worst thing to ever happen to React. They're so easy to get starte... (28)

yeneek on Dec 17, 2020 | parent | prev | next [–]


A lot of successful people use Cobol too

Hooks are the worst thing to ever happen to React. They're so easy to get starte... (29)

eitland on Dec 17, 2020 | root | parent | next [–]


Yep, but not voluntarily on greenfield projects unless I'm missing out on the latest trends from the Valley ;-)

Hooks are the worst thing to ever happen to React. They're so easy to get starte... (30)

yeneek on Dec 17, 2020 | root | parent | next [–]


Fair enough.Still "successful people use it, so it must be good" isn't a valid argument for me.

Hooks are the worst thing to ever happen to React. They're so easy to get starte... (31)

onion2k on Dec 17, 2020 | prev | next [–]


Junior engineers are also constantly tripped up by the subtleties of `useEffect` and `useState`.

They are, but they're also tripped up by the subtleties of class-based React components. The difference is that with hooks it's really obvious when they've tripped up (because React can tell, and warns you) while with classes it's really not obvious at all. This is one place where hooks are a clear win.

Hooks are the worst thing to ever happen to React. They're so easy to get starte... (32)

joekrill on Dec 17, 2020 | prev | next [–]


Hooks are not some panacea that's going to fix a defunct development process or poor code organization and management.

Any codebase, using any language, framework, feature, and technology, needs to be managed properly. There's really no getting around that. And without that, you're almost always going to end up with things turning into something along the lines of "complete untestable spaghetti". Especially when you have junior developers involved. Hooks are no different, nor is the entire Javascript landscape.

In general these complaints are getting tiring and often feel like they are coming from folks who don't have the appropriate level of experience or knowledge in a particular subject area to be making these generalizations. I don't know what your level of competence is, but this line:

> Look, I get that Redux was a pain in the ass with all the boilerplate, but how did we throw the baby (unidirectional data flow) out with the bathwater.

gives me pause, because Hooks aren't meant to replace Redux in any way. There are hooks that maintain state, sure, but generally they're meant to replace class component lifecycle functions. Hooks and Redux still coexist quite well.

Hooks are the worst thing to ever happen to React. They're so easy to get starte... (33)

knuthsat on Dec 17, 2020 | prev | next [–]


I think hooks and effects are really good. You can test them separately. You can write global reactions to state changes very easily.

I find hooks/effects better than mobx or redux. hooks/effects, redux, mobx would be my preference order. Although redux works so well that it can be used with hooks/effects.

For global state I would just use a React.Context with it's own effects. Most components do not have any async effects.

I do admit that when jumping into a new codebase with hooks/effects I often find people have just butchered the concept. But I find that when I jump into codebases with mobx and redux too. The butchering that people do with mobx is much worse, with massive module importing of global stores, misuse of `name?: type` inside stores because they want to initialize the store at a later time.

Hooks are the worst thing to ever happen to React. They're so easy to get starte... (34)

postalrat on Dec 17, 2020 | parent | next [–]


IMO the new context and hook are the best thing that react has done. Hats off to whoever designed them.

Hooks are the worst thing to ever happen to React. They're so easy to get starte... (35)

knuthsat on Dec 17, 2020 | root | parent | next [–]


Yep. I've watched the video that @BreakfastB0b referenced and must say I do not see how this can't be done with new hooks/effects.

I can easily have all the user settings accessed inside a small effect and react to events or not depending on the settings and it's composable and reusable.

Testing with jest/enzyme is still the same. I'm writing selectors, simulating clicks and the component rerenders. Mocking the effects or functions that effects use is also simple. With jest 26 and modern fake timers it's easy to test async effects and changes of state too.

I guess the only flaw of hooks/effects is that they not efficient because of so many effects fetching the same state but they are efficient enough. For example, mobx would be extremely efficient in that regard (any store.value access is just that, not a useState call with new () => {} instantiated on every rerender.

Hooks are the worst thing to ever happen to React. They're so easy to get starte... (36)

BreakfastB0b on Dec 17, 2020 | parent | prev | next [–]


 You can write global reactions to state changes very easily.

This is exactly the problem, shared mutable state leads to "spooky action at a distance". It results in causal connections between parts of your codebase that are not reflected in the control flow of your code. If you have immutable unidirectional data flow causal relationships between parts of your code base must be reified in the control flow of the language.

 Most components do not have any async effects.

At least when using Apollo / GraphQL almost every component ends up with async effects.

I think this talk by Andre Staltz is the best explanation and solution of the problem https://www.youtube.com/watch?v=SXdtrhn8iII

Hooks are the worst thing to ever happen to React. They're so easy to get starte... (37)

knuthsat on Dec 17, 2020 | root | parent | next [–]


But the state is not mutable, the state is inside a React.Context that provides functions that manipulate it. It's practically the same as redux. You still need to have async actions with redux and use these actions.

mobx on the other hand is exactly that, the state is globally mutable, anyone can import it from anywhere to anywhere.

Hooks are the worst thing to ever happen to React. They're so easy to get starte... (38)

azangru on Dec 17, 2020 | prev | next [–]


> Junior engineers are also constantly tripped up

That's just the nature of being a junior engineer — you get tripped up. Tripped up by mutating objects, by stale closures, by comparing numbers to strings, by asynchrony, by thinking in terms of rxjs or xstream streams, by god knows what else.

Hooks are the worst thing to ever happen to React. They're so easy to get starte... (39)

fn1 on Dec 17, 2020 | parent | next [–]


So let's write code in a way that doesn't trip up junior engineers...

That will also help seniors when they are tired or under time-pressure.

Hooks are the worst thing to ever happen to React. They're so easy to get starte... (40)

true_religion on Dec 17, 2020 | root | parent | next [–]


Sure and if you are at a big company like Facebook that makes total sense. However lots of us work for smaller firms. My company has no junior engineers.

Hooks are the worst thing to ever happen to React. They're so easy to get starte... (41)

ljm on Dec 17, 2020 | prev | next [–]


The problem I see with hooks is how they replace one set of problems with another, and demand you structure your code in a way to avoid those pitfalls. You know, how to structure conditional code, how to use loops when dealing with hooks, having to think about function object equality, having to supply the functions and variables your callback/effect closes over as dependencies (I still don't understand why you would do some of that in favour of pulling your callback out of the component)... and for what? For it all to change in another year or so when the JS community starts hankering for another paradigm?

Lately when working with all this I feel as if the same code would be simpler and easier to follow if it wasn't shoehorned into JS. It's like the uncanny valley of functional programming.

But more fundamentally, dealing with frontend application code is mentally exhausting in a way I haven't experienced before. I feel like I'm no longer learning Javascript as a language, but just keeping up with the novel abstraction of the month.

I should add that I don't hate it, and there's plenty still to appreciate. Some of it is a joy and it's refreshing to work on projects that embrace more functional styles over the typical CRUD and OOP taxonomy construction you get in a typical backend job. Different set of problems once you get away from the typical framework stuff (react, redux, saga boilerplate).

Hooks are the worst thing to ever happen to React. They're so easy to get starte... (42)

wongarsu on Dec 17, 2020 | parent | next [–]


I feel like that's more a complaint about the JS frontend ecosystem as a whole. Every paradigm has its own pitfalls and idioms, and at least to me hooks seem better than class components most of the time. You exchange one set of pitfalls with another, and get more pleasant, more composable behavior overall. But compared to many GUI frameworks in other languages it still feels like a mess, and it's a mess that constantly changes from under you.

Hooks are the worst thing to ever happen to React. They're so easy to get starte... (43)

ljm on Dec 17, 2020 | root | parent | next [–]


You're absolutely right. The native platforms aren't perfect, but they're stable and successful.

Hooks are the worst thing to ever happen to React. They're so easy to get starte... (44)

qudat on Dec 18, 2020 | prev | next [–]


As someone who architects FE codebases for a living I both agree and disagree with you.

React hooks definitely threw a wrinkle in the testability of react components. However, the ideas around how the FE should be tested has changed to the point where current thinking is that integration tests are the most valuable tests you can write. Testing what a react component does in isolation of redux or its side-effects is easy to do and also not incredibly useful.

Furthermore, many modern codebases still use redux. I still advocate for it. Using hooks and redux are not mutually exclusive.

I wish there was something better than hooks, it’s very easy to forget a dependency or get into infinite loops, but they do make life much easier. No more mapStateToProps or mapDispatchToProps HoCs. No more “smart” vs “dumb” components. No more function/class components. There’s only one component.

Also, we are seeing an increase in “headless” react libraries, where the logic of some functionality is disconnected from the visual design of a set of components. It makes composition, extendability, and maintainability much easier.

Hooks are the worst thing to ever happen to React. They're so easy to get starte... (45)

yeneek on Dec 17, 2020 | prev [–]


Happy that someone other than me sees that too. I predict that companies will start leaving React in 5 years. React will have the same fate as AngularJS and jQuery.

Hooks are the worst thing to ever happen to React. They're so easy to get starte... (2024)

FAQs

Are React hooks a bad idea? ›

So why are they bad? Hooks indirectly make functions that should be pure by passing the state in a “magical way” compared to the old school HOC/class component approaches. React's initial idea was to have a one-way data flow, but this idea is basically destroyed with hooks.

Why are React hooks needed? ›

Hooks were added to React in version 16.8. Hooks allow function components to have access to state and other React features. Because of this, class components are generally no longer needed.

When not to use React hooks? ›

🔴 Do not call Hooks inside conditions or loops. 🔴 Do not call Hooks after a conditional return statement. 🔴 Do not call Hooks in event handlers. 🔴 Do not call Hooks in class components.

Is useEffect bad for React? ›

The use of useEffect in React applications is not inherently bad. It is a crucial part of the React Hooks system that is meant to deal with side effects (like data fetching, subscriptions, timers, manual DOM manipulations, etc.) in functional components.

What is incorrect about React Hooks? ›

Incorrect Usage

function Component() { if (condition) { const [state, setState] = useState(initialState); } // ... } Hooks must always be invoked in the same order during every component render. This helps promotes more predictable and stable component behavior.

Are Hooks still used in React? ›

React provides a few built-in Hooks like useState . You can also create your own Hooks to reuse stateful behavior between different components. We'll look at the built-in Hooks first. You can learn more about the State Hook on a dedicated page: Using the State Hook.

Why use Hooks instead of classes? ›

The use of hooks enables the creation of functional components without the requirement for classes, making the code simpler to read and comprehend. Hooks produce better code by removing the hassle of handling the `this` keyword, constructor, and lifecycle functions.

Why Hooks instead of lifecycle methods? ›

React hooks provide a more concise way to manage state and side effects in functional components. Lifecycle methods are only available in class components and can hook into various stages of a component's lifecycle.

Should I learn all React Hooks? ›

The Benefits of Using Hooks

Hooks have a lot of benefit to us as developers, and they are going to change the way we write components for the better. They already help us to write clearer and more concise code - it's like we went on a code diet and we lost a lot of weight and we look better and feel better.

What can I use instead of Hooks React? ›

In the quest for performance optimization in React applications, Signals emerge as a compelling alternative to React Hooks. By decoupling state management and offering granular control over rendering, Signals empower developers to build scalable, efficient, and maintainable applications.

What is the general rule of Hooks? ›

The first guideline is that hooks should only be called at the top level of your React methods. This means that hooks should not be called within loops, conditions, or nested functions. This rule ensures that the hooks are called in the same order every time a component is rendered.

When should Hooks be used? ›

Don't call Hooks inside loops, conditions, or nested functions. Instead, always use Hooks at the top level of your React function, before any early returns.

Is React poor for SEO? ›

React is an excellent platform for building complex applications with beautiful UI. However, the framework wasn't built to be optimized for SEO. If you're looking to make your next web app on React, you'll need to use dependencies and libraries to optimize your project for the search engine.

Why not to use React Redux? ›

One of the main drawbacks of using Redux is the added complexity it brings to an application. In order to use Redux, developers must become familiar with concepts such as actions, action creators, and reducers, which can be difficult to understand and can add a learning curve to the development process.

Why is angular worse than React? ›

FAQs About Angular vs React

React uses one-way data binding and virtual DOM, whereas Angular uses two-way data binding and real DOM. Moreover, React is faster than Angular as it has a smaller bundle size.

Is React hook form worth using? ›

Between the simple API, small size, and React hook approach, React Hook Form makes building, validating, and testing forms in React straightforward. In summary, React Hook Form leverages React hooks to create a lightweight but powerful form management library. If you build forms in React, it's worth giving a try!

Are React custom Hooks useful? ›

Custom Hooks in React are a powerful feature that allows us to extract component logic into reusable functions. These Hooks are JavaScript functions that can use other Hooks provided by React. They enable us to organize logic into separate, reusable modules.

Is React Hooks better than Redux? ›

Redux and React Hooks should be seen as complements and also as different things. While with the new React Hooks additions, useContext and useReducer, you can manage the global state, in projects with larger complexity you can rely on Redux to help you manage the application data.

Are React Hooks better than classes? ›

Using hooks will solve many of the problems which we often experience while using React Classes, but there are still some cases like we cannot access lifecycle methods while using hooks.

Top Articles
Latest Posts
Article information

Author: Tish Haag

Last Updated:

Views: 5553

Rating: 4.7 / 5 (47 voted)

Reviews: 86% of readers found this page helpful

Author information

Name: Tish Haag

Birthday: 1999-11-18

Address: 30256 Tara Expressway, Kutchburgh, VT 92892-0078

Phone: +4215847628708

Job: Internal Consulting Engineer

Hobby: Roller skating, Roller skating, Kayaking, Flying, Graffiti, Ghost hunting, scrapbook

Introduction: My name is Tish Haag, I am a excited, delightful, curious, beautiful, agreeable, enchanting, fancy person who loves writing and wants to share my knowledge and understanding with you.