Skip to content

Commit

Permalink
Merge pull request #2 from zvoverman/api-testing
Browse files Browse the repository at this point in the history
code cleanup
  • Loading branch information
zvoverman authored May 21, 2024
2 parents 3792dac + bc475db commit 6ac1cf7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>React App</title>
<title>React + Typescript App!</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
Expand Down
9 changes: 6 additions & 3 deletions src/components/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ function GetPeople() {
const [favoriteCards, setFavoriteCards] = useState<number[]>([]);
const [showFavorites, setShowFavorites] = useState<boolean>(false);

const queryClient = useQueryClient()

// Get list of favorites from dyamoDB
const { isLoading, error, data } = useQuery<CharacterData[]>('people', () =>
// Lambda API Gateway
fetch('https://w5c9dy2dg4.execute-api.us-east-2.amazonaws.com/people', {
headers: {
'Content-Type': 'application/json',
Expand All @@ -43,13 +43,16 @@ function GetPeople() {
)
);

// Updates the local favorites list
useEffect(() => {
if (data) {
setFavoriteCards(data.map(person => parseInt(person.id)));
}
}, [data]);

console.log(favoriteCards);
if (isLoading) return (<p>Loading...</p>);

if (error) return (<p>Error fetching data.</p>);

const handleInputChange = (event: React.ChangeEvent<HTMLInputElement>) => {
const value = parseInt(event.target.value);
Expand Down

0 comments on commit 6ac1cf7

Please sign in to comment.