My question is regarding including an array that doesn't stop loading even when using useEffect. Other questions do not cover this topic; they cover similar but different approaches.
I am fetching data from my firebasefirestore and setting the data required.
Now I only need the data to run once and to be displayed, but when i use the useEffect hook with the dependency (it doesn't work without the dependency), it starts running continuously and i can see in the network tab that it keeps on fetching the data non stop.
How can I fix this, what can i do to make my useEffect run only once even if it has a dependency array.
Here is my code:
import React, { Component, useEffect, useState, useCallback } from "react";
const [agentData, setAgentData] = useState([]);
const [agentID, setAgentID] = useState("");
const getSalesAgentInformation = async () => {
await firebase
.firestore()
.collection("Employees")
.where("employeeID", "==", agentID)
.get()
.then((snapshot) => {
const salesAgent = snapshot.docs.map((doc) => doc.data());
setAgentData(salesAgent);
});
};
useEffect(() => {
getSalesAgentInformation();
}, [agentData]);