You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I discovered a bug where, if the user rapidly clicks on multiple cards, they remain flipped even though no match has actually occurred. However, this issue can be resolved with a simple adjustment in the handleCardClick function. Here’s the updated code snippet:
functionhandleCardClick(card: Card){if(card.isFlipped||card.isMatched)return;// this lineconstisFlippedMaximumCardsAtSameTime=cards.filter(card=>card.isFlipped&&!card.isMatched).length===2;if(isFlippedMaximumCardsAtSameTime)return;setCards((prevCards)=>{constnewCards=[...prevCards];newCards[card.id].isFlipped=true;constflippedCards=newCards.filter((c)=>c.isFlipped&&!c.isMatched,);if(flippedCards.length===2){handleCardMatch(flippedCards[0],flippedCards[1]);}returnnewCards;});}
The text was updated successfully, but these errors were encountered:
pedrolgcs
changed the title
Flip multiplos cards ate same time in - [solving react interview questions]
Flip multiplos cards at same time in - [solving react interview questions]
Feb 11, 2025
I discovered a bug where, if the user rapidly clicks on multiple cards, they remain flipped even though no match has actually occurred. However, this issue can be resolved with a simple adjustment in the handleCardClick function. Here’s the updated code snippet:
The text was updated successfully, but these errors were encountered: