Получаю данные из базы в NodeJS таким образом:
const Router = require('express')
const router = new Router()
const {Worker} = require('../models/models')
const sequelize = require('../db')
module.exports = function (app) {
app.get('/', async (req, res) => {
let {fio, department, position, phonenumber} = req.query
let workers;
workers = await Worker.findAll();
res.json(workers);
});
}
Получаю массив [{"id":1,"fio":null,"department":null,"position":null,"phonenumber":null,"createdAt":"2022-07-21T04:21:51.992Z","updatedAt":"2022-07-21T04:21:51.992Z"}]
Как его вывести в файле App.js? Код файла:
import React, {useEffect, useState} from 'react'
import './App.css';
function App() {
const [data, setData] = useState();
useEffect(() => {
fetch("http://localhost:5000")
.then(
(result) => {
setData(result)
},
(error) => {
}
)
}, []);
console.log(data)
return (
<div className="App">
</div>
);
}
export default App;