Gen1Code / Chess-Lights-Out

https://chess-lights-out.vercel.app
GNU General Public License v3.0
1 stars 0 forks source link

Following up on react-chessboard open issue #119 #2

Closed GuillaumeSD closed 4 weeks ago

GuillaumeSD commented 4 weeks ago

Hi,

Following up on your message here : https://github.com/Clariity/react-chessboard/issues/119#issuecomment-2293317366

I think the issue you are seeing comes at least from this : https://github.com/Gen1Code/Chess-Lights-Out/blob/919d3aef896f04dac4cd9da5ffbc135033065e28/frontend/src/context/GameContext.jsx#L122

The useEffect dependencies array has response in it while it uses setResponse in its execution. Therefore it should trigger an infinite loop that loads the game indefinitely.

A good React practice is to never set a state in a useEffect if it is in its dependencies array.

Gen1Code commented 4 weeks ago

That is not the case, no infinite loop is created. It's an intended feature to request the actual game state and deal with appropriately if the server responds the user is already in a game