2021-03-04
2274
#react
Sonny Recio
35517
Mar 4, 2021 â‹… 8 min read

The noob’s guide to useState

Sonny Recio 10% Entrepreneur | Fitness Junkie | Software Engineer | Fullstack web developer | Game Developer | Article writer and musician | Lifelong learner

Recent posts:

Rxjs Adoption Guide: Overview, Examples, And Alternatives

RxJS adoption guide: Overview, examples, and alternatives

Get to know RxJS features, benefits, and more to help you understand what it is, how it works, and why you should use it.

Emmanuel Odioko
Jul 26, 2024 â‹… 13 min read
Decoupling Monoliths Into Microservices With Feature Flags

Decoupling monoliths into microservices with feature flags

Explore how to effectively break down a monolithic application into microservices using feature flags and Flagsmith.

Kayode Adeniyi
Jul 25, 2024 â‹… 10 min read
Lots of multi-colored blue and purplish rectangles.

Animating dialog and popover elements with CSS @starting-style

Native dialog and popover elements have their own well-defined roles in modern-day frontend web development. Dialog elements are known to […]

Rahul Chhodde
Jul 24, 2024 â‹… 10 min read
Using Llama Index To Add Personal Data To Large Language Models

Using LlamaIndex to add personal data to LLMs

LlamaIndex provides tools for ingesting, processing, and implementing complex query workflows that combine data access with LLM prompting.

Ukeje Goodness
Jul 23, 2024 â‹… 5 min read
View all posts

10 Replies to "The noob’s guide to <code>useState</code>"

  1. Honestly, most of this article is pretty useless. Anyone who has read the “getting started” of hooks won’t do any of this. Only the part about not passing setValue to the children might be a real world case.

    It’s a bit preposterous to say that I’m using it wrong and then make a list of super obvious mistakes that honestly, the incredible minority of newbies would do.

    Clickbait article, wasted my time.

  2. Title should be “I was using use state wrong”
    It would be very hard to make some of those mistakes if you read the React documentation.

  3. Been working with hooks since they were released, reviewed thousands of PRs.
    Never saw even one of this cases.

  4. Not even that was realistic, why would someone use a prop to pass a function that can be easily imported.

  5. Yeah this article is pointless and clickbaity. I was like “oh what am I doing wrong?” and I thought it would be a best practice thing like don’t use too many useStates or use somethinge else. Then it was just like “don’t change the state directly” which is the first thing you learn.

  6. The first example isn’t really valid is it? You can’t reassign a constant, and that’s the point of declaring it that way.

  7. The point displayed by example in the section “Not putting useState at the top of component body or functions” is wrong.
    By top level the React documentation does not mean the line number but the nesting of hooks inside other elements. Both given examples are completely valid.
    As long as your hook is on top level you can put in any working location of your component.

Leave a Reply