بنقرة واحدة
optimize-react-component
Optimize React components for performance following Next.js 15 and project best practices
التثبيت باستخدام Codex أو Claude انسخ هذا Prompt والصقه في Codex أو Claude أو مساعد آخر ليراجع صفحة Skill ويثبّتها لك.
القائمة
Optimize React components for performance following Next.js 15 and project best practices
التثبيت باستخدام Codex أو Claude انسخ هذا Prompt والصقه في Codex أو Claude أو مساعد آخر ليراجع صفحة Skill ويثبّتها لك.
استنادا إلى تصنيف SOC المهني
Add a new Recharts visualization with theme-aware styling to the dashboard
Add a new metric card to the dashboard with proper styling and components
Add Lucide React icons to components following project conventions
Add responsive layouts following mobile-first design principles with Tailwind CSS
Add a new shadcn/ui component to the project following the New York style variant
Add or customize theme colors in the CSS custom properties system
| name | optimize-react-component |
| description | Optimize React components for performance following Next.js 15 and project best practices |
When optimizing React components in this Next.js 15 dashboard:
Choose the right component type:
Minimize client-side JavaScript:
// Good: Server Component (default)
export default function StaticContent() {
return <div>Content</div>;
}
// Use client only when necessary
"use client";
export default function InteractiveContent() {
const [state, setState] = useState(false);
return <div onClick={() => setState(!state)}>Content</div>;
}
Optimize re-renders with React.memo and useMemo:
import { memo, useMemo } from "react";
// Memoize expensive computations
const ExpensiveComponent = memo(function ExpensiveComponent({ data }) {
const processedData = useMemo(() => {
return data.map(item => expensiveOperation(item));
}, [data]);
return <div>{processedData}</div>;
});
Use dynamic imports for large components:
import dynamic from "next/dynamic";
const HeavyChart = dynamic(() => import("@/components/HeavyChart"), {
loading: () => <p>Loading chart...</p>,
ssr: false // Disable SSR if component uses browser APIs
});
Optimize images with next/image:
import Image from "next/image";
<Image
src="/image.png"
alt="Description"
width={500}
height={300}
priority // For above-the-fold images
/>
Prevent unnecessary effect executions:
// Include all dependencies
useEffect(() => {
fetchData(id);
}, [id]); // Specify dependencies
// Cleanup side effects
useEffect(() => {
const subscription = subscribe();
return () => subscription.unsubscribe();
}, []);
Type safety for better performance:
any typeComponent splitting:
Leverage Turbopack (Next.js 15):
npm run dev which automatically uses Turbopack// Before (unnecessarily client-side)
"use client";
export default function StaticCard() {
return <Card>Static Content</Card>;
}
// After (server component)
export default function StaticCard() {
return <Card>Static Content</Card>;
}
"use client";
import { memo, useMemo } from "react";
import { LineChart, Line } from "recharts";
export const OptimizedChart = memo(function OptimizedChart({ data }) {
const colors = useChartColors();
// Memoize processed data
const chartData = useMemo(() => {
return data.map(item => ({
name: item.label,
value: item.total
}));
}, [data]);
return (
<LineChart data={chartData}>
<Line dataKey="value" stroke={colors.chart1} />
</LineChart>
);
});
// Before: One large component
export default function Dashboard() {
return (
<div>
<Header />
<Stats />
<Charts />
<Footer />
</div>
);
}
// After: Split into smaller, focused components
export default function Dashboard() {
return (
<div>
<DashboardHeader />
<DashboardStats />
<DashboardCharts />
<DashboardFooter />
</div>
);
}
// Each component in its own file
// Easier to maintain, optimize, and test
next.config.tstsconfig.jsonsrc/components/DashboardCharts.tsxcreate-dashboard-pageadd-chart