Next.js Discord

Discord Forum

How to useState with SSR components?

Answered
Turkish Angora posted this in #help-forum
Open in Discord
Turkish AngoraOP
Trying to create an off canvas menu and I want to track state of whether it is open or closed using { useState } however Next throws an error saying I can only use it on client components.

How do I get around this?
Answered by Brown bear
put 'use client' at the very top of your file had the same problem
View full answer

2 Replies

create a client component and use the hooks there. client components are still pre-rendered on the server so this is completely fine
Answer