How to useState with SSR components?
Answered
Turkish Angora posted this in #help-forum
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?
How do I get around this?
Answered by Brown bear
put 'use client' at the very top of your file had the same problem
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
@Turkish Angora 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?
Brown bear
put 'use client' at the very top of your file had the same problem
Answer