DEV Community

Discussion on: Creating A Memory Game With React

Collapse
lukeshiru profile image
Luke Shiru

A few things I noticed:

  • In Card you shouldn't need id and handleClick. The parent should already know the id, so sending it down just to send it back up again is kinda pointless.
  • You should use button instead of div.
  • Having an empty string as an alt for an image to please the a11y linter is not a good practice, you should put some description there.
  • The array of images could be moved out of the component and simplified to avoid duplication.
  • If you can write prev and a comment explaining it means previous, you can just write previous. Same applies for stat that is one letter away from state, or 2 away from status, either way you're not saving time 🤣
  • When you do items[value].stat you're doing a mutation, and you should avoid those. If you really want to do it that way, you should use tools such as immer.
  • You shouldn't use index as a key, instead you should use something that identifies the item (like an id).

Here's a CodeSandbox with this fixes applied to it:

Cheers!