تابع useEffect تابع async بعنوان ورودی قبول نمی کند. برای این کار باید یک تابع async تعریف کنیم و آن را در ورودی تابع useEffect فراخوانی کنیم. به صورت زیر:
useEffect(() => {
// declare the data fetching function
const fetchData = async () => {
const data = await fetch('https://example.com');
// ...
setData(data)
await anotherFunction()
}
// call the function
fetchData()
}, [])
رای
0
ارسال نظر
مرتب سازی:
اولین نفری باشید که نظر می دهید!