Next.js Discord

Discord Forum

What is wrong with my client component?

Unanswered
Allegheny mound ant posted this in #help-forum
Open in Discord
Allegheny mound antOP
I added the useEffect() hook in a client component, and now it throws me the error:

Error: Invalid hook call. Hooks can only be called inside of the body of a function component.

7 Replies

Allegheny mound antOP
I just fetches widgets form the API using React Query, and sets the first widget it received as the current value.
Seems like useEffect has an issue with useQuery?
Not sure you can do that
@Clown Not sure you can do that
Allegheny mound antOP
Why wouldn't it be possible?
Do you actually use useEffect in Next?

The code seems to work without it, but I learned to use useEffect from vanilla React.
Yes you can use it in NextJS
Allegheny mound antOP
It works fine without useEffect, but not sure if it's good code like this.