0

I am relatively new to Next.js. Trying out version 13.1 and the new app directory.

Is it possible to do so? Without losing the new benefits of server controls?

I see the following error:

You're importing a component that needs useState. It only works in a Client Component but none of its parents are marked with "use client", so they're Server Components by default.
Youssouf Oumar
  • 29,373
  • 11
  • 46
  • 65
ps.
  • 4,230
  • 5
  • 31
  • 39
  • 1
    Does this answer your question? [You're importing a component that needs useState. It only works in a Client Component, but none of its parents are marked with "use client"](https://stackoverflow.com/questions/74965849/youre-importing-a-component-that-needs-usestate-it-only-works-in-a-client-comp) – Youssouf Oumar Jan 16 '23 at 21:40

1 Answers1

0

The useState hook only runs on the client. In case your component uses it consider adding the “use client” directive at the top of the component file. This will pre-render your markup on the server and run the ‘useState’ hook after the rehydration.

Laszlo
  • 2,225
  • 19
  • 22