How to avoid infinite loop? I mean in the first click the StudentSubject must be undefined, and in the second click it will get the data, in my current code the result are infinite loop, it keeps looping the console.log(getStudentId, getRelevance)
how to avoid that?
const [getStudentId, setStudentId]= useState();
const [getRelevance, setRelevance]= useState();
useEffect(() => {
student();
}, []);
const onClickGrade = (studentId, relevance) => {
.....
console.log(getStudentId, getRelevance) //undefined
if(StudentSubject === undefined){
onClickGrade(studentId, relevance) //infinite loop
}
....
}
const student = () => {
.....
view.on('click', onClickMap);
.....
}
const onClickStudent = (event)=>{
const studentId = student.getAttribute('id');
const relevance = student.getAttribute('relevance');
setStudentId(studentId)
setRelevance(relevance)
onClickGrade(studentId, relevance)
}