2
my code:
import React, { Component } from 'react'
import axios from 'axios'
import PageHeader from '../template/pageHeader'
import cadastroForm from './cadastroForm'
import cadastroList from './cadastroList'
const URL = 'http://localhost:3003/api/cadastros'
export default class Cadastro extends Component {
constructor(props) {
super(props);
this.state = { listaItens: [] }
this.refresh()
}
refresh(Nome = '') {
const search = Nome ? `&Nome__regex=/${Nome}/` : ''
axios.get(`${URL}?sort=-createdAt${search}`)
.then(response => { this.setState({ listaItens: response.data}); })
.catch(() => { console.log('Erro ao recuperar os dados'); });
}
render() {
return (
<div>
{this.state.listaItens.map(function(item) {console.log(item)})}
</div>
)
}
}
returns: