No vídeo o instrutor mencionou que podemos fazer o consumo da API com fetch API, eu tentei aplicar, mas nao estou conseguindo, poderiam me ajudar? =D
import React, { useState } from 'react';
import {
UserRegisterContainer,
UserRegisterTable,
UserRegisterTableHead,
UserRegisterTableSupport,
UserRegisterTableTitle,
UserRegisterTableBody,
UserRegisterTableContent
} from './styles';
const UserRegister = () => {
const [lists, setLists] = useState([{}]);
const URL_AUTHORS = 'https://cdc-react.herokuapp.com/api/autores/';
new Promise((resolves, reject) => {
fetch(URL_AUTHORS, {
method: 'GET',
})
.then(data => {
if(data) {
data.json();
}
else {
reject();
}
})
.catch(error => {
reject();
})
})
return (
<UserRegisterContainer>
<UserRegisterTable>
<UserRegisterTableHead>
<UserRegisterTableSupport>
<UserRegisterTableTitle>Nome</UserRegisterTableTitle>
<UserRegisterTableTitle>E-mail</UserRegisterTableTitle>
</UserRegisterTableSupport>
</UserRegisterTableHead>
<UserRegisterTableBody>
{[lists.map((list, key) => (
<UserRegisterTableSupport key={key}>
<UserRegisterTableContent>{list.name}</UserRegisterTableContent>
<UserRegisterTableContent>{list.email}</UserRegisterTableContent>
</UserRegisterTableSupport>
))]}
</UserRegisterTableBody>
</UserRegisterTable>
</UserRegisterContainer>
)
}
export default UserRegister;