Next.js Discord

Discord Forum

Layout can't use useState.

Answered
Mugger Crocodile posted this in #help-forum
Open in Discord
Mugger CrocodileOP
Layout does not support usestate, so how to place dynamic js? Just like that dark or light theme for common header.
Thank you.
Answered by riský
layout does support useState if you make it client by adding 'use client' at top
View full answer

6 Replies

layout does support useState if you make it client by adding 'use client' at top
Answer
but most cases it can be better to keep the layout server and make client page you import into it (and thus keep metadata): https://nextjs-faq.com/metadata-client-components
@Mugger Crocodile is your question answerd, or do you have some more questions?
Mugger CrocodileOP
solved. I create a component and then import it.
#closed
@riský
@Mugger Crocodile <@657067112434499595>
yay, enjoy the rest of the day!