Skip to content

Instantly share code, notes, and snippets.

@andersonFaro9
Created March 5, 2023 10:02
Show Gist options
  • Save andersonFaro9/a052676ef809a7619797049aa1edd8f4 to your computer and use it in GitHub Desktop.
Save andersonFaro9/a052676ef809a7619797049aa1edd8f4 to your computer and use it in GitHub Desktop.
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