Quantcast
Channel: Форум программистов и сисадминов Киберфорум
Viewing all articles
Browse latest Browse all 520367

Почему на сервер беспрерывно поступают get запросы? - JavaScript: ReactJS

$
0
0
Я еще новичок в JS да и вовсе в программировании, так что не кидайтесь камнями пожалуйста и объясните почему при таком коде на мой сервер беспрерывно поступают гет запросы?

Это клиентская часть.
:

import React, {useState} from 'react';
import axios from 'axios';
import TableLine from "./components/TableLine";
import './App.css'



function App() {
    const [prices, setPrices] = useState([])

    async function getGoods(){
        const response = await axios.get('http://localhost:3000')
        setPrices(response.data)
    }

    getGoods()

    return(
        <div className="Marakooya">
            <table>
                <tbody>
                    {prices.map((price, index) => <TableLine key={index} data={price}/>)}
                </tbody>
            </table>
        </div>
    )
}

export default App;

А это сервер.
:

import express from 'express'
import mysql from 'mysql2'
import cors from 'cors'

const connection = mysql.createConnection({
    host: 'localhost',
    user: 'root',
    database: 'database'
})

const app = express();

app.use(
    cors({
        origin: '*'
    }
))

app.get('/', (req,res) => {
    connection.query('SELECT * from prices', (err, result, fields) => {
        console.log(result)
        res.json(result)
    })
})

app.listen(3000, () => {
    console.log('server started on port 3000')
})


Viewing all articles
Browse latest Browse all 520367

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>