Menu

'use client' Doesn't Turn Your Whole App Into a Client Component (The Children Trick Nobody Explains)
📰

'use client' Doesn't Turn Your Whole App Into a Client Component (The Children Trick Nobody Explains)

DEV Community: react·Anas Sheikh·5 days ago
#cOZlR1tS
#devtoreact#devto#dev#client#server
Reading 0:00
15s threshold

You need a theme provider, so you create a file, add 'use client' at the top, and wrap your app in it.

Then a nagging thought arrives: "I just wrapped my entire layout in a client component. Did I turn the whole app into client-side React?"

Most developers either panic and avoid providers, or give up and put 'use client' at the top of every file "just to be safe". Both are the wrong response, and the actual rule is simpler than you expect.

The Setup

// components/ThemeProvider.tsx ' use client ' ;

import { createContext , useState } from ' react ' ;

export const ThemeContext = createContext ( ' light ' );

export function ThemeProvider ({ children }: { children : React .…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.