Created
February 2, 2023 13:19
-
-
Save pytqqq/ac17a0bd6ef76b5821e7b78f04f77e20 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const GameList = () => { | |
const {isLoading, data} = useGetGames(); | |
const [gameLikes, setGameLikes] = React.useState<any>({}); | |
const likeGame = (id: number) => { | |
setGameLikes((prevState: any) => { | |
return { | |
...prevState, | |
[id]: prevState[id] ? prevState[id] + 1 : 1, | |
}; | |
}); | |
}; | |
return isLoading ? ( | |
<Box | |
flex={1} | |
backgroundColor="black" | |
alignItems="center" | |
justifyContent="center"> | |
<Spinner color="purple.500" size="lg" testID="spinner" /> | |
</Box> | |
) : ( | |
<View testID="list"> | |
<Box> | |
{data?.pages | |
?.map((page: {results: any}) => page.results) | |
.flat() | |
.map((game: any) => ( | |
<GameItem | |
game={game} | |
likes={gameLikes[game.id]} | |
likeFn={() => likeGame(game.id)} | |
/> | |
))} | |
</Box> | |
</View> | |
); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment