fac18 / react_game-rosa-pat-

react game
https://react-game-pat-and-rosa.netlify.com/
0 stars 2 forks source link

Stateless/Statefull #12

Open tonylomax opened 4 years ago

tonylomax commented 4 years ago

In your cards.js file you store your clickedCards in an array. You don't seem to get any weird issues because of this but you're doing sort of the opposite of react - doing mutations without states. Have you tried putting this array in a state and updating it with a addToClickCards function or something on line 15?

tonylomax commented 4 years ago

You could then actually put this stuff in a useEffect hook and set it to change when this array changes. So your flow is something like: Click ➝ call addToClickCards() ➝ array length is changed ➝ useEffect hook triggered by array change ➝ state of clickedcards array is checked and toggles the class

tonylomax commented 4 years ago

Sorry many comments but it's all related. It's the same thing in your header file, you have a function that's returning an array you're calling setPhotoArray function with but really I think that array should be another state. Any time you have data that's changing you have a stateful component, even if this is probably only changing when you refresh/reload to play a game it's still worth bearing in mind