Skip to content

Instantly share code, notes, and snippets.

@pytqqq
Created February 2, 2023 13:19
Show Gist options
  • Save pytqqq/ac17a0bd6ef76b5821e7b78f04f77e20 to your computer and use it in GitHub Desktop.
Save pytqqq/ac17a0bd6ef76b5821e7b78f04f77e20 to your computer and use it in GitHub Desktop.
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