1
When you require something from the backend, the return comes as an empty array.
I tried both with map and with console log.. Source code:
Reportscreen.js
const [reports, setReports ] = useState([]);
useEffect(() => {
async function loadReports() {
const response = await api.get('/reports');
setReports(response.data);
console.log(reports);
}
loadReports();
}, []);
The backend is sending the data with paging for the bank (Mongodb), I do not know if it can be the problem, and if it is not know how to solve.
Return of the requisition:
Edit:
api.js
import axios from 'axios';
const api = axios.create({
baseURL: 'http://10.0.2.2:3001/api'
});
export default api;
reportController.js
async list(req, res) {
const reports = await Report.paginate({}, { page: 1, limit: 10});
return res.json(reports);
}
Edit 2:
server.js
const express = require('express');
const mongoose = require('mongoose');
const requireDir = require('require-dir');
const cors = require('cors');
const app = express();
app.use(express.json());
app.use(cors());
mongoose.connect(
'mongodb://localhost:27017/vendedorpositivo-backend',
{ useUnifiedTopology: true, useNewUrlParser: true }
);
requireDir('./src/models');
app.use('/api', require("./src/Routes"));
app.listen(3001);
Upload the api code and backend chunk. In Insomnia the right return, returns the data.
– Matheus Costa
Are you using express to make this api? It shows the main file 'server.js' or 'app.js'
– hnrqss
I put in question the server.js :)
– Matheus Costa
hnrqss, is there a social network I can talk to you about? To with some difficulty in all backend and frontend integration...
– Matheus Costa
Linkedin: https://www.linkedin.com/in/hnrqsss/
– hnrqss