I'm getting this too many re-renders error when I'm running this, this is in react. I ve already searched on many forums but still no luck. I know why this is happening because I ve used setState in useEffect, and is looping.
useEffect(() => {
getClassData();
}, []);
//setClassData(stateData);
const getClassData = ()=> {
axios.post(`${apiEndPoint}/get/class/student`, ApiData, {
headers: headers
}).then(response => {
const classArray = response.data;
stateData=classArray;
setClassData(classArray);
})
.catch(err => {
console.log(err)
})
}
console.log(stateData);
return(
<ClassListGenerator classArrayData={classData}/>
)
};
question from:
https://stackoverflow.com/questions/65952717/too-many-re-renders-on-react 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…