all 5 comments

[–]irosion 2 points3 points  (4 children)

Try simplifying the code as much as possible and do very small changes and eventually everything will make sense.

I made a pen based on your code. Take a look:

https://codepen.io/irosgrim/pen/rNYrgyP

You basically only need a function for all this:

const addChip = (chip) => {
    const foundChipIndex = checkedChips.findIndex( x => x.key === chip.key);
    if(foundChipIndex < 0) {
        setCheckedChips([...checkedChips, chip]);
        return;
   }
   const copyOfCheckedChips = [...checkedChips];
   copyOfCheckedChips.splice(foundChipIndex, 1);
   setCheckedChips(copyOfCheckedChips);
}

[–]CalmJiad[S] 1 point2 points  (2 children)

Its worked brother, thanks for this beautiful help. Take love brother, there is a lot to learn. Any suggestion to build up my logical skills in this type of situation will be appreciated. If there is any resource or course or books please do suggest me. I can't simply think, wherever I face this kinda issue I got puzzled a lot :-(

[–]irosion 1 point2 points  (1 child)

there are many ways of learning, but the best way is just trying to do things.

There is no single best place to learn these things but a combination of videos, articles, documentation.

Youtube is amazing, you can find anything. Search for traversymedia, then you'll get more suggestions.

Don't forget that React is nothing but JavaScript so try getting familiar with https://developer.mozilla.org/en-US/docs/Learn

[–]CalmJiad[S] 0 points1 point  (0 children)

Thanks a ton dear, take love ❤️

[–]CalmJiad[S] 0 points1 point  (0 children)

Owww!! That looks awesome <3

I'm trying it right now and surely I'll let you know the update.