I am beginners in React.Js
I don't know why useEffect is calling an API multiple time without any Dependency
If There any other Way to do it Please Suggest Me
Pages File : /pages/dashboard/speaking/[slug].js
} else if(slug == "repeat-sentence") {
if (userData.role == "Admin") {
return (<> <AdminRepeatSentence /> </>);
} else if(userData.role == "Teacher") {
return (<> <TeacherRepeatSentece /> </>);
} else if(userData.role == "Student") {
return (<> <StudentRepeatSentece /> </>);
}
Component File : /components/dashboard/speaking/repeat-sentence.js
export function StudentRepeatSentece(params) {
const [para, setPara] = useState();
useEffect(() => {
const handlePara = async () => {
console.log(">>>>>>>>>>>>>>>fetching Have Been Start");
const res = await fetch("/api/speaking/read-aloud");
console.log(">>>>>> Fetch API <<<<<<<<<<");
const data = await res.json();
console.log(data);
setData(data.para);
console.log(">>>>>>>>> Convert Json <<<<<<<<");
};
handlePara();
}, []);
return (<> <SecondComponent myPara={para}/> </> );
}
Children Component
function SecondComponent({myPara}) {
// Some Code Will Be Here
useEffect(()=> {
speak(myPara);
}, [myPara]);
retunr (<>someCode
{myPara}
Some Code
</>);
}