Nick Bull Blog

Nick Bull Blog

3 Mistakes Every React Beginners Make (are you one of them?)

3 Mistakes Every React Beginners Make (are you one of them?)

1. Forget that setState is asynchronous

Even experienced folks forget about that.

Let’s take a look at this example.

Image for post

Always keep in mind:

setState is async. setState is async. setState is async.

As you can see from the example above we can safely call any function after the state is updated via setState callback.

setState({ age: value }, () => {
    // state is updated and you can safely perfom any action here
})

2. Forget how setState works in functional components

If you’re just starting with React hooks, you can easily forget that setState here doesn’t work the same way as in the class components.

setState from class components automatically merges the previous state with the new one.

setState from functional components don’t do this.

Image for post

The right way to use setState in functional components is to combine previous state value with the new updates.

Image for post

3. Using React when you don’t need it

Love this.

Remember: You don’t need ReactJS in most cases.

One page app? Don’t need it.

Blog? Don’t need it.

Large complex app? It depends.

Learn the basics first. And you will understand when and why you need to use React.

In the end

Choose technologies by the problem you try to solve.

Don’t choose something because it’s popular right now.

That’s all. Thanks!

🔴 Get more coding tips, job interview advice, and the latest tech news. Join my Newsletter

#javascript#reactjs#developer#advice#frontend-development
 
Share this