Created
February 5, 2023 12:41
-
-
Save andersonFaro9/b313f0862c33343531833d94e6a21c9c 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
import Head from 'next/head' | |
import Image from 'next/image' | |
import { useEffect, useState } from 'react'; | |
import {api} from './api/api' | |
interface IBooks { | |
title: string; | |
} | |
export default function Home() { | |
const [books, setBook] = useState<IBooks>(); | |
const getBooks = async () => { | |
try { | |
const myBooks = await api.get("/books").then((response) => setBook(response.data)) | |
console.log(myBooks) | |
}catch(err) { | |
console.error(err) | |
} | |
} | |
useEffect( () => { | |
getBooks() | |
}, []) | |
return ( | |
<> | |
<ul> | |
{books?.title} | |
{/* {books.map((book) =>{<li key = {book.id}>{book.title}</li>})} */} | |
</ul> | |
</> | |
) | |
} | |
// O axios | |
import axios from 'axios'; | |
export const api = axios.create({ | |
baseURL: 'http://localhost:3000', | |
}) | |
export default api; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment