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 on a bubbly orange background. Guide on building adaptive and responsive UIs in React Native for diverse devices.

Creating adaptive and responsive UIs in React Native

Design React Native UIs that look great on any device by using adaptive layouts, responsive scaling, and platform-specific tools.

Chinwike Maduabuchi
Nov 15, 2024 â‹… 9 min read
Enhancing Two-Way Data Binding In Angular

Enhancing two-way data binding in Angular

Angular’s two-way data binding has evolved with signals, offering improved performance, simpler syntax, and better type inference.

Alexander Godwin
Nov 14, 2024 â‹… 6 min read
Hand holding purple sticky notes for CSS sticky positioning guide.

Troubleshooting CSS sticky positioning

Fix sticky positioning issues in CSS, from missing offsets to overflow conflicts in flex, grid, and container height constraints.

Ibadehin Mojeed
Nov 13, 2024 â‹… 5 min read
Task Scheduling and cron Jobs in Node Using node-cron

Scheduling tasks in Node.js using node-cron

From basic syntax and advanced techniques to practical applications and error handling, here’s how to use node-cron.

Godwin Ekuma
Nov 12, 2024 â‹… 7 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