1
2 Comments

The Most Common Mistakes When Using React

https://claritydev.net/blog/the-most-common-mistakes-when-using-react

Discover common React mistakes that developers make when using hooks, managing state, and rendering components. Learn how to identify and fix these mistakes to improve your application's performance and maintainability.

submitted this linkon April 12, 2023
  1. 1

    Good article. However you have broken the rule 'Incorrectly relying on the current state value for calculating the next state' inside 'Working with simple arrays'.

    You shouldn't have

    setItems([...items, item]);

    but instead

    setItems((items) => [...items, item]);

    1. 1

      In that specific case it's actually not necessary to use the updater function since React will correctly handle the update.