أنماط التركيب لمكوّنات الخادم والعميل
تعلّم كيفية تركيب Server Components وClient Components بشكل صحيح، وتمرير Server Components كعناصر children لتجنب تضخيم حزمة العميل.
أنماط التركيب لمكوّنات الخادم والعميل درس مجاني في Next.js 15 Fullstack (App Router + Server Actions) على CoddyKit. هذا هو الدرس 4 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في Next.js 15 Fullstack (App Router + Server Actions)، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة Next.js 15 Fullstack (App Router + Server Actions) 4 دروس في المجموع.
بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.
The Composition Challenge
You often need interactivity (Client) wrapping data-heavy UI (Server). The trick is composing them so Server Components are not pulled into the client bundle.
The One-Way Rule
A Client Component cannot import a Server Component, because importing would force it to run on the client. But it can render one passed as children.
Passing as Children
Render a Server Component inside a Client Component by passing it through props from a parent Server Component.
export default function Page() {
return (<ClientShell><ServerContent /></ClientShell>);
}The Client Shell
The Client Component receives the already-rendered Server output as children and never needs to know how it was built.
"use client";
export default function ClientShell({ children }) {
const [open, setOpen] = useState(false);
return (<div>{children}<button onClick={() => setOpen(!open)}>Toggle</button></div>);
}Why This Works
The Server Component renders on the server; only its output (serialized RSC payload) reaches the client. The Client Component just slots it in — no server code shipped.
Props Must Be Serializable
Props passed from Server to Client Components must be serializable. You cannot pass functions, class instances, or Dates without care — but you can pass plain data and JSX children.
Moving Client Boundaries Down
Keep "use client" as deep in the tree as possible. A small leaf Client Component keeps most of the tree server-rendered and the bundle small.
Context Providers
Client context providers wrap Server children fine: define the provider as a Client Component and pass server-rendered children through it.
"use client";
export function ThemeProvider({ children }) {
return <Ctx.Provider value={theme}>{children}</Ctx.Provider>;
}Avoiding Accidental Client Code
Importing a library that uses browser APIs into a Server Component breaks it. Isolate such code behind a Client Component boundary.
Interleaving Example
You can deeply interleave: Server layout, Client sidebar toggler, Server content, Client like-button — each boundary minimal and intentional.
Mental Model
Think of Client Components as holes in a server-rendered tree. Data flows down as props/children; interactivity lives only where needed.
Quick Check
How do you render a Server Component inside a Client Component?
Recap
You learned the key composition pattern: Client Components cannot import Server Components but can render them as children. Keep client boundaries small and deep, pass serializable props, and treat Client Components as interactive holes in a server-rendered tree.
تعلم TypeScript مع معلم ذكاء اصطناعي — مجانًا
اكتب وقم بتشغيل أكوادك الفعلية في المتصفح، واحصل على مساعدة فورية من معلم ذكاء اصطناعي متاح 24/7، واستمر من حيث توقفت على الويب أو في التطبيق.
- الدورات
- 22
- الدروس
- 88
الأسئلة الشائعة
هل درس «أنماط التركيب لمكوّنات الخادم والعميل» مجاني؟
نعم — نص درس «أنماط التركيب لمكوّنات الخادم والعميل» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة Next.js 15 Fullstack (App Router + Server Actions)، انتقل إلى CoddyKit PRO. تتضمن دورة Next.js 15 Fullstack (App Router + Server Actions) 4 دروس في المجموع.
ماذا ستتعلم في «أنماط التركيب لمكوّنات الخادم والعميل»؟
تعلّم كيفية تركيب Server Components وClient Components بشكل صحيح، وتمرير Server Components كعناصر children لتجنب تضخيم حزمة العميل. تتمرن على Next.js 15 Fullstack (App Router + Server Actions) مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.
هل أحتاج إلى خبرة سابقة لأبدأ Next.js 15 Fullstack (App Router + Server Actions)؟
لا تُشترط خبرة سابقة. Next.js 15 Fullstack (App Router + Server Actions) على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 4 من أصل 4.
كم من الوقت يستغرق درس «أنماط التركيب لمكوّنات الخادم والعميل»؟
معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.
هل يمكنني كتابة وتشغيل أكواد في درس Next.js 15 Fullstack (App Router + Server Actions) هذا؟
نعم. كل درس في Next.js 15 Fullstack (App Router + Server Actions) يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.
جميع الدروس في هذه الدورة
- فهم RSC وRCC
- جلب البيانات في RSC
- التفاعلية باستخدام RCC
- أنماط التركيب لمكوّنات الخادم والعميل