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:

React logo over a beige background

Data fetching with Remix’s loader function

Learn how Remix enhances SSR performance, simplifies data fetching, and improves SEO compared to client-heavy React apps.

Abhinav Anshul
Nov 26, 2024 â‹… 5 min read
Top 8 Fullstory Competitors And Alternatives

Top 8 Fullstory competitors and alternatives

Explore Fullstory competitors, like LogRocket, to find the best product analytics tool for your digital experience.

Jeff Wharton
Nov 26, 2024 â‹… 13 min read

Adapting to user motion and theme preferences with CSS and JavaScript

Learn how to balance vibrant visuals with accessible, user-centered options like media queries, syntax, and minimized data use.

Oscar Jite-Orimiono
Nov 25, 2024 â‹… 5 min read
Vue logo over a brown background.

A guide to two-way binding in Vue

Learn how to implement one-way and two-way data binding in Vue.js, using v-model and advanced techniques like defineModel for better apps.

David Omotayo
Nov 22, 2024 â‹… 10 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