Created
March 5, 2023 10:02
-
-
Save andersonFaro9/a052676ef809a7619797049aa1edd8f4 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 { useEffect, useState } from 'react' | |
import {api} from './api/api' | |
interface IDescription { | |
description:string; | |
id:string; | |
} | |
export default function Details () { | |
const [details, setDetails] = useState<IDescription[]>([]); | |
useEffect( ()=>{ | |
getDetails() | |
},[]) | |
async function getDetails () { | |
try { | |
const response = await api.get('books/', { | |
params: { | |
details, | |
}, | |
}) | |
setDetails (response.data) | |
} | |
catch(error) { | |
console.log(error) | |
} | |
} | |
if (!details) { | |
return <div>carregando...</div> | |
} | |
return ( | |
<div> | |
{details.map((item)=> | |
(<li key = {item.id}> | |
<p>{item.description}</p> | |
</li> | |
))} | |
</div> | |
) | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment