Created
September 8, 2020 18:11
-
-
Save fredarend/c571d2b2fd88c734997a757bac6ab766 to your computer and use it in GitHub Desktop.
DevList
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 React, { useEffect, useState } from 'react'; | |
import { FiEdit, FiXCircle } from 'react-icons/fi'; | |
import { Container, DevContainer, Dev, Info, Techs, Actions } from './styles'; | |
import api from '../../../services/api'; | |
type Technologies = any[]; | |
interface DevelopersData { | |
id: number; | |
name: string; | |
email: string; | |
age: number; | |
url_linkedin: string; | |
technologies: Technologies; | |
} | |
const DevList: React.FC = () => { | |
const [developers, setDevelopers] = useState<DevelopersData[]>([]); | |
const getDevelopers = async () => { | |
await api.get('/developers').then(response => { | |
setDevelopers(response.data); | |
}); | |
}; | |
useEffect(() => { | |
getDevelopers(); | |
}, [developers]); | |
console.log(developers); | |
return ( | |
<Container> | |
<DevContainer> | |
{developers.map(developer => ( | |
<Dev key={developer.id}> | |
<Info> | |
<h1>{developer.name}</h1> | |
<p>{developer.email}</p> | |
<p> | |
{developer.age} | |
<span> anos</span> | |
</p> | |
</Info> | |
<Techs> | |
{developer.technologies.map(techs => ( | |
<span key={techs.id}>{techs.name}</span> | |
))} | |
</Techs> | |
<Actions> | |
<button type="button"> | |
<FiEdit size={18} /> | |
</button> | |
<button type="button"> | |
<FiXCircle size={18} /> | |
</button> | |
</Actions> | |
</Dev> | |
))} | |
</DevContainer> | |
</Container> | |
); | |
}; | |
export default DevList; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment