Skip to content
Advertisement

TypeError: func.apply is not a function

I’m trying to use useEffect function like that:

JavaScript

But when I try to use data variable it sometimes throws this error:

JavaScript

I don’t know, where do I miss.

Advertisement

Answer

You can only pass a normal function as argument to useEffect, and not an async function. In order to use async await in useEffect, you can write your function as an IIFE (Immediately Invoked Function Expression – you write the function and call it immediately).

JavaScript

Or you can just create a normal named async function and then call it as below,

JavaScript
Advertisement