DEV Community

Discussion on: The most common mistakes when using React

Collapse
 
victorcorcos profile image
Victor Cordeiro Costa • Edited

I found an error on the second code snipped. You passed the idx as a parameter, but you used the id instead.

The corrected code...

    const updateFeaturesList = (e, id) => {
      const { checked } = e.target;
      setListFeatures(features => {
        return features.map((feature, index) => {
          if (id === index) {
            feature = { ...feature, checked };
          }
          return feature;
        });
      });
    };

It is just a minor thing, though

Collapse
 
clarity89 profile image
Alex K.

A sharp eyed reader! :) Thank you, I'll fix it :)

Collapse
 
victorcorcos profile image
Victor Cordeiro Costa

Hehehe, thank you!
By the way, Great post!!
I am learning React from scratch right now and this was in particular useful! <3

Thread Thread
 
clarity89 profile image
Alex K.

Thank you and good luck! :) Be sure to also check the official documentation, it has more details about the points I mentioned.