I am working on a create-react-app generated app and I have an API call to a local JSON file. Somehow this code generates 8 API calls in a roll.
import '@css/request.scoped.css';
import { useState } from 'react';
import { getAllData } from '@api/api';
function Request() {
let [user, setUser] = useState('');
function changeUser(data) {
setUser(data);
}
getAllData().then((reply) => {
changeUser(reply.data[0].item_name);
});
return <>{user}</>;
}
export default Request;
and here is my Axios instance
import axios from "axios";
const request = axios.create({
baseURL:'./example.json',
timeout: 20000,
});
export const getAllData = () => {
return request({
method: 'get',
url: '',
});
};
Can someone tell me why this happens?