state updating problem

Hello



recently i made a custom hook that fetches the user from the db and another one that fetches data from an external api.

Basically this api returns a chess fen a chess position on the chessboard and the possible moves around 8 moves i passed the fen as a prop to the chessboard component and make it as an initial value to the fen state i did that because the fen will change during the game until the moves are null.

For testing i hard coded a fen and a moves vars and everything worked fine but when i switched to the custom hook it breaks as follows :
When i console.log The fen state it logs undefined and nothing shows on the board ui and i think because its related to the state and the async behavior but i couldn't find a good way to make the initial state not undefined.

here's some code snippets to explain more:
Was this page helpful?