xiaohongshu
xiaohongshu
bellog-rsc
Provides guidance on React Server Components vs Client Components decision-making in Bellog. Triggers when creating new components.
Full skill instructions
This skill defines when to use Server Components vs Client Components in the Bellog blog project.
Default to Server Components. Only use Client Components when necessary.
Does the component need interactivity or browser APIs?
│
├─ NO (static rendering)
│ └─ ✅ Server Component
│ - Fast initial load
│ - Zero client JavaScript
│ - Can use async/await directly
│ - Can access server-only APIs
│ - Better SEO
│
└─ YES (hooks, events, browser APIs)
└─ 🔴 Client Component ("use client")
- Can use hooks (useState, useEffect, etc.)
- Can attach event handlers
- Can access browser APIs
- Can use framer-motion
- Can use next-themes
✅ Use Server Components when:
// ✅ Server Component (no "use client")
import { getAllPosts } from '@/lib/posts';
export default async function PostList() {
// Can use async/await directly
const posts = await getAllPosts();
return (
<div>
{posts.map(post => (
<PostCard key={post.id} post={post} />
))}
</div>
);
}
Server Components:
app/page.tsx - Home page (fetches recent posts)app/posts/page.tsx - Posts list (fetches all posts)app/posts/[slug]/page.tsx - Post detail (fetches single post)PostList component - Renders static post gridPostCard component - Static card rendering🔴 Use Client Components when you need:
1. React Hooks:
useState, useEffect, useContextuseRef, useCallback, useMemouseScrollSpy, etc.)2. Event Handlers:
onClick, onChange, onSubmitonScroll, onMouseEnter, onMouseLeave3. Browser APIs:
window, document, localStorageIntersectionObserver, ResizeObservernavigator, location4. Third-Party Libraries:
"use client"; // Required at top of file
import { useState } from 'react';
import { motion } from 'framer-motion';
export function InteractiveCard() {
const [isHovered, setIsHovered] = useState(false);
return (
<motion.div
onMouseEnter={() => setIsHovered(true)}
onMouseLeave={() => setIsHovered(false)}
whileHover={{ scale: 1.02 }}
>
{/* Interactive content */}
</motion.div>
);
}
Client Components:
Navbar.tsx - Scroll detection, theme toggleIntro.tsx - TypeAnimation, framer-motionNotionToc.tsx - Scroll spy, active section trackingtemplate.tsx - Page transition animationsThemeToggle.tsx - next-themes integrationProgressBar.tsx - Scroll progress trackingGiscusComments.tsx - Comment system (requires client JS)Best Practice: Keep most as Server, wrap interactive parts as Client.
// app/posts/[slug]/page.tsx (Server Component)
import { getPostBySlug } from '@/lib/posts';
import { NotionToc } from '@/components/posts/NotionToc'; // Client
import { PostNavigation } from '@/components/posts/PostNavigation'; // Client
import { PostRenderer } from '@/components/posts/PostRenderer'; // Server
export default async function PostPage({ params }) {
const post = await getPostBySlug(params.slug);
return (
<div>
<NotionToc headings={post.headings} /> {/* Client island */}
<PostRenderer content={post.content} /> {/* Server */}
<PostNavigation prev={post.prev} next={post.next} /> {/* Client */}
</div>
);
}
// Server Component
async function ParentServer() {
const data = await fetchData(); // Server-side fetch
return <ChildClient data={data} />; // Pass as props
}
// Client Component
"use client";
function ChildClient({ data }) {
const [selected, setSelected] = useState(data[0]);
// Use data in client component
}
Important: Don't pass functions or Date objects - serialize data!
// ❌ Wrong
<ClientComponent date={new Date()} />
// ✅ Correct
<ClientComponent date={new Date().toISOString()} />
Wrap Client Component to Reduce Bundle:
// Layout (Server Component)
import { ClientHeader } from './ClientHeader';
export function Layout({ children }) {
return (
<>
<ClientHeader /> {/* Only this is client */}
<main>{children}</main> {/* Can be server */}
</>
);
}
import { cache } from 'react';
// Deduplicates requests within a single render
export const getPost = cache(async (id: string) => {
return await fetchPost(id);
});
import { cache } from 'react';
import { unstable_cache } from 'next/cache';
export const getAllPosts = cache(
unstable_cache(
async () => {
return await getAllPostsFromNotion();
},
['all-posts'], // Cache key
{
revalidate: 3600, // 1 hour
tags: ['posts', 'notion']
}
)
);
Example from /src/lib/posts.ts:
export const getAllPosts = cache(
unstable_cache(
async () => {
const posts = await getAllPostsFromNotion();
return posts.sort((a, b) =>
new Date(b.date).getTime() - new Date(a.date).getTime()
);
},
["all-posts"],
{
revalidate: 3600, // Revalidate every hour
tags: ["posts", "notion"]
}
)
);
// app/api/revalidate/route.ts
import { revalidateTag } from 'next/cache';
export async function POST(request: Request) {
const secret = request.nextUrl.searchParams.get('secret');
if (secret !== process.env.REVALIDATION_SECRET) {
return Response.json({ message: 'Invalid' }, { status: 401 });
}
revalidateTag('notion'); // Invalidate all Notion caches
return Response.json({ revalidated: true });
}
// ❌ Wrong (doesn't need "use client")
"use client";
export function StaticCard({ title, description }) {
return (
<div>
<h3>{title}</h3>
<p>{description}</p>
</div>
);
}
// ✅ Correct (Server Component)
export function StaticCard({ title, description }) {
return (
<div>
<h3>{title}</h3>
<p>{description}</p>
</div>
);
}
// ❌ Wrong (needs "use client" because of useState)
import { useState } from 'react';
export function Counter() {
const [count, setCount] = useState(0); // Error!
return <button onClick={() => setCount(count + 1)}>{count}</button>;
}
// ✅ Correct
"use client";
import { useState } from 'react';
export function Counter() {
const [count, setCount] = useState(0);
return <button onClick={() => setCount(count + 1)}>{count}</button>;
}
// ❌ Wrong (Client Components can't be async)
"use client";
export default async function Page() {
const data = await fetchData(); // Error!
return <div>{data}</div>;
}
// ✅ Correct (Server Component)
export default async function Page() {
const data = await fetchData();
return <ClientChild data={data} />;
}
// ❌ Wrong (functions can't be serialized)
async function ServerComponent() {
const handler = () => console.log('click');
return <ClientComponent onClick={handler} />; // Error!
}
// ✅ Correct (define handler in client component)
"use client";
function ClientComponent() {
const handler = () => console.log('click');
return <button onClick={handler}>Click</button>;
}
When creating a component, ask:
If any checkbox is true, use "use client". Otherwise, keep as Server Component.
Bundle Size: 0 KB (no client JavaScript) Initial Load: Fast (pre-rendered HTML) Hydration: None needed SEO: Excellent (fully rendered)
Bundle Size: Adds JavaScript to bundle Initial Load: Slower (needs hydration) Hydration: Required SEO: Good (but requires hydration)
Example:
Navbar.tsx (Client): ~5 KBIntro.tsx with framer-motion (Client): ~30 KBPostList (Server): 0 KB// Always start here
export function Component() {
// ...
}
// Only add "use client" when needed
// ✅ Good - Only button is client
function Page() {
return (
<div>
<StaticContent /> {/* Server */}
<InteractiveButton /> {/* Client */}
</div>
);
}
// ❌ Bad - Everything is client
"use client";
function Page() {
return (
<div>
<StaticContent /> {/* Unnecessary client */}
<InteractiveButton />
</div>
);
}
// ✅ Extract interactive part
function ServerCard({ data }) {
return (
<div>
<StaticHeader data={data} /> {/* Server */}
<InteractiveActions id={data.id} /> {/* Client */}
</div>
);
}
"use client";
function InteractiveActions({ id }) {
const [liked, setLiked] = useState(false);
return <button onClick={() => setLiked(!liked)}>Like</button>;
}
// Layout stays Server
function Layout({ children }) {
return (
<>
<Header /> {/* Client component */}
<main>{children}</main> {/* Can be Server */}
<Footer /> {/* Server component */}
</>
);
}
// Server Component (default)
export async function Component() {
const data = await fetchData();
return <div>{data}</div>;
}
// Client Component (when needed)
"use client";
import { useState } from 'react';
export function Component() {
const [state, setState] = useState();
return <button onClick={() => setState(...)}>Click</button>;
}
// Client with framer-motion
"use client";
import { motion } from 'framer-motion';
export function Component() {
return <motion.div animate={{ opacity: 1 }}>...</motion.div>;
}
// Pass data Server → Client
function Server() {
const data = await fetch();
return <Client data={data} />; // Serialize data
}
Remember: Every "use client" adds to bundle size. Be intentional about where you place client boundaries.
xiaohongshu
technical spec
product ux expert
database patterns
Conduct multi-agent task orchestration and workflow coordination.
Initialize project with Conductor artifacts (product definition,
Expert in web animations, transitions, and motion design using Framer Motion and CSS
Creates Mermaid and ASCII diagrams for flowcharts, architecture, ERDs, state machines, mindmaps, and more. Use when user mentions diagram, flowchart, mermaid, ASCII diagram, text diagram, terminal diagram, visualize, C4, mindmap, architecture diagram, sequence diagram, ERD, or needs visual docume...
PostgreSQL bindings for H3 hexagonal grid system. Use when working with H3 cells in Postgres, including spatial indexing, geometry/geography integration, and raster analysis.
Context-Driven Development skill for projects using Conductor. Use this skill when you detect a `conductor/` directory in the project, when working on tasks defined in a `plan.md` file, or when the user asks about tracks, specs, or plans. Automatically applies TDD workflow, tracks task completion...
Display project status, active tracks, and next actions
Official Stakpak application containerization standard operating procedure, a step-by-step guidline to properly dockerize applications. This is a rule book curated by the Stakpak Team.
Generate, edit, and beat-sync AI video with leading models in one workspace.
The world's fastest calendar for remote work
Transform Your Design with AI Designer by ImgCreator.ai
Revolutionizing Video Production with AI-Powered Creativity
Extend an image past the frame and let AI fill the new aspect ratio.
Discover your celebrity doppelgänger with StarByFace!
ChainClarity explains 700+ crypto whitepapers in plain English, with layered summaries, comparisons, research tools, alerts, and a $4.99 Pro plan.
Opus.ai: Revolutionize Your Web Experience