Next.js Discord

Discord Forum

What is wrong with my client component?

Unanswered
Allegheny mound ant posted this in #help-forum
Open in Discord
Avatar
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.
Image

7 Replies

Avatar
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?
Image
Avatar
Not sure you can do that
Avatar
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.
Avatar
Yes you can use it in NextJS
Avatar
Allegheny mound antOP
It works fine without useEffect, but not sure if it's good code like this.
Image