I'm having a problem with my get request function using Axios. whenever its got called, the get function always runs twice. I don't know what the problem is here. I have tried removing React.Strictmode tag but nothing changed. I started to think the webpack dev server is the problem here. Here is my code :
- my get Request function :
export default async function useSendResquest(url, handler) {
var Response;
Response = await axios.get(url).then((response) => {
return response.data;
});
return handler(Response);
}
- My UseEffect Call :
useEffect(() => {
useSendResquest(
"http://localhost:8080/api/control?name=rgbLed&status",
(Response) => {
setLightState(Response);
}
);
console.log("hi");
}, []);
- Network activity :
does anyone have any clue?
Thank you all


varuseletinsteadvarwithletor even betterconst? It might be unrelated, above all it's a good practice, but I do have a sneaking suspicion given it exists in global scope the response actually gets instantiated twice, first as the global initialization of var and then whatever gets passed by the return of theaxioscall, hence causing component to re-mount with updated state anduseEffectrunning twice.