name: component-integration
description: React, MDX, and Tailwind CSS integration patterns for Astro websites. Use when adding React components, configuring MDX content, setting up Tailwind styling, integrating component libraries, building interactive UI elements, or when user mentions React integration, MDX setup, Tailwind configuration, component patterns, or UI frameworks.
allowed-tools: - Read
- Write
- Edit
- Bash
- Glob
- Grep
Component Integration
Comprehensive patterns for integrating React components, MDX content, and Tailwind CSS into Astro websites with type safety, performance optimization, and best practices.
Overview
This skill provides:
- React component integration with Astro islands architecture
- MDX configuration for content-rich component authoring
- Tailwind CSS setup with custom design systems
- Type-safe component patterns with TypeScript
- Performance optimization techniques
- Component library integration (shadcn/ui, Radix, etc.)
Setup Scripts
Core Setup Scripts
- scripts/setup-react.sh - Initialize React integration in Astro project
- scripts/setup-mdx.sh - Configure MDX support with plugins
- scripts/setup-tailwind.sh - Install and configure Tailwind CSS
- scripts/validate-integration.sh - Validate component integration setup
- scripts/optimize-components.sh - Apply performance optimizations
Utility Scripts
- scripts/generate-component.sh - Scaffold new React components
- scripts/add-component-library.sh - Integrate shadcn/ui or other libraries
Templates
React Component Templates
- templates/react/basic-component.tsx - Simple React component with TypeScript
- templates/react/interactive-component.tsx - Interactive component with state
- templates/react/island-component.tsx - Astro island with client directives
- templates/react/form-component.tsx - Form component with validation
- templates/react/data-fetching-component.tsx - Component with async data
- templates/react/component-with-context.tsx - Context provider pattern
MDX Templates
- templates/mdx/basic-mdx.mdx - Basic MDX file structure
- templates/mdx/mdx-with-components.mdx - MDX using custom components
- templates/mdx/mdx-layout.astro - Layout wrapper for MDX content
- templates/mdx/remark-plugin.js - Custom remark plugin template
Tailwind Templates
- templates/tailwind/tailwind.config.ts - Full Tailwind configuration
- templates/tailwind/custom-theme.ts - Custom design system theme
- templates/tailwind/base-styles.css - Base CSS with custom utilities
- templates/tailwind/component-variants.ts - CVA variant patterns
Integration Templates
- templates/integration/astro-config-full.ts - Complete Astro config
- templates/integration/tsconfig-components.json - TypeScript config for components
- templates/integration/package-json-deps.json - Required dependencies
Examples
- examples/basic-integration.md - Simple React component in Astro
- examples/mdx-blog-post.md - MDX blog post with components
- examples/tailwind-design-system.md - Custom Tailwind design system
- examples/interactive-forms.md - Forms with validation and state
- examples/component-library-integration.md - shadcn/ui setup guide
- examples/performance-optimization.md - Islands architecture best practices
- examples/type-safe-patterns.md - TypeScript patterns for components
Instructions
Phase 1: Initial Setup
Assess Current Setup
# Check existing integrations
bash scripts/validate-integration.sh
Install Required Integrations
# Setup React
bash scripts/setup-react.sh
# Setup MDX
bash scripts/setup-mdx.sh
# Setup Tailwind
bash scripts/setup-tailwind.sh
Validate Installation
- Check astro.config.mjs for integrations
- Verify package.json dependencies
- Test basic component rendering
Phase 2: Component Development
Generate Component Structure
# Create new component
bash scripts/generate-component.sh ComponentName --type interactive
Apply Templates
- Use templates/react/* for React components
- Use templates/mdx/* for content components
- Use templates/tailwind/* for styling patterns
Implement Type Safety
- Define component props interfaces
- Use TypeScript strict mode
- Export component types for consumers
Phase 3: Styling Integration
Configure Tailwind Theme
- Read: templates/tailwind/tailwind.config.ts
- Customize colors, fonts, spacing
- Add custom utilities and variants
Create Component Variants
- Use CVA (class-variance-authority) pattern
- Read: templates/tailwind/component-variants.ts
- Define size, color, and style variants
Setup Base Styles
- Read: templates/tailwind/base-styles.css
- Add custom CSS variables
- Define global typography styles
Phase 4: MDX Configuration
Setup MDX Processing
- Configure remark and rehype plugins
- Read: templates/mdx/remark-plugin.js
- Add syntax highlighting, image optimization
Create MDX Layouts
- Read: templates/mdx/mdx-layout.astro
- Design consistent content layouts
- Add frontmatter-based customization
Register Custom Components
- Map components to MDX elements
- Read: templates/mdx/mdx-with-components.mdx
- Enable rich content authoring
Phase 5: Performance Optimization
Apply Islands Architecture
- Use client:* directives strategically
- Read: examples/performance-optimization.md
- Minimize client JavaScript
Optimize Component Loading
bash scripts/optimize-components.sh
Implement Code Splitting
- Use dynamic imports for heavy components
- Lazy load below-the-fold content
- Defer non-critical interactions
Phase 6: Component Library Integration
Add Component Libraries
# Add shadcn/ui
bash scripts/add-component-library.sh shadcn-ui
Configure Library Theming
- Integrate library tokens with Tailwind
- Customize component defaults
- Ensure consistent design language
Create Wrapper Components
- Wrap library components for Astro compatibility
- Add project-specific defaults
- Maintain type safety
Best Practices
React Integration
- Use Islands Architecture: Only hydrate interactive components
- Minimize Bundle Size: Import only needed components
- Type Everything: Use TypeScript interfaces for all props
- Avoid Layout Shift: Reserve space for hydrated components
- Handle SSR: Ensure components work server-side
MDX Content
- Separate Content from Logic: Keep MDX focused on content
- Use Frontmatter: Add metadata for routing and SEO
- Component Consistency: Reuse components across MDX files
- Optimize Images: Use Astro Image optimization
- Test Rendering: Validate MDX compiles correctly
Tailwind Styling
- Design Tokens: Define colors, spacing in config
- Utility Classes: Prefer utilities over custom CSS
- Component Variants: Use CVA for variant management
- Responsive Design: Mobile-first approach
- Dark Mode: Configure dark mode variant strategy
Performance
- Static First: Generate static HTML by default
- Selective Hydration: Use client:visible, client:idle
- Bundle Analysis: Monitor JavaScript bundle sizes
- CSS Optimization: Purge unused Tailwind classes
- Image Optimization: Use Astro Image component
Common Patterns
Pattern 1: Interactive Island Component
// Component with selective hydration
import { useState } from 'react';
interface Props {
initialCount?: number;
}
export default function Counter({ initialCount = 0 }: Props) {
const [count, setCount] = useState(initialCount);
return (
<button => setCount(count + 1)}>
Count: {count}
</button>
);
}
Usage in Astro:
---
import Counter from '@/components/Counter';
---
<Counter client:visible initialCount={5} />
Pattern 2: MDX with Custom Components
---
title: "Blog Post with Components"
---
import { Alert } from '@/components/Alert';
# My Blog Post
<Alert type="info">
This is custom component in MDX
</Alert>
Pattern 3: Tailwind Variant Component
import { cva, type VariantProps } from 'class-variance-authority';
const buttonVariants = cva(
'rounded-md font-medium transition-colors'
{
variants: {
variant: {
primary: 'bg-blue-600 text-white hover:bg-blue-700'
secondary: 'bg-gray-200 text-gray-900 hover:bg-gray-300'
}
size: {
sm: 'px-3 py-1.5 text-sm'
md: 'px-4 py-2 text-base'
lg: 'px-6 py-3 text-lg'
}
}
defaultVariants: {
variant: 'primary'
size: 'md'
}
}
);
type ButtonProps = VariantProps<typeof buttonVariants> & {
children: React.ReactNode;
};
export function Button({ variant, size, children }: ButtonProps) {
return (
<button className={buttonVariants({ variant, size })}>
{children}
</button>
);
}
Troubleshooting
React Components Not Hydrating
Problem: Components render statically but don't have interactivity
Solution:
- Add client directive:
client:load, client:visible, or client:idle
- Ensure component is exported as default
- Check for SSR-incompatible code (window, document)
MDX Compilation Errors
Problem: MDX files fail to compile
Solution:
- Validate MDX syntax (closing tags, component imports)
- Check remark/rehype plugin compatibility
- Ensure imported components are available
- Review astro.config.mjs MDX configuration
Tailwind Classes Not Applied
Problem: Tailwind utilities not working in components
Solution:
- Check tailwind.config.ts content paths include component files
- Import Tailwind base styles in layout
- Verify PostCSS configuration
- Clear Astro cache:
rm -rf .astro
Type Errors in Components
Problem: TypeScript errors in React components
Solution:
- Review templates/integration/tsconfig-components.json
- Ensure @types/react is installed
- Check jsx compiler options
- Validate component prop interfaces
Related Skills
- content-collections: Use for structured content with type safety
- performance-optimization: Additional performance patterns
- testing-patterns: Testing React components in Astro
Requirements
- Node.js 18+
- Astro 4.0+
- React 18+
- Tailwind CSS 3.4+
- TypeScript 5.0+
Plugin: website-builder
Version: 1.0.0
1---2name: component-integration3description: React, MDX, and Tailwind CSS integration patterns for Astro websites. Use when adding React components, configuring MDX content, setting up Tailwind styling, integrating component libraries, building4---5
6---
7name: component-integration
8description: React, MDX, and Tailwind CSS integration patterns for Astro websites. Use when adding React components, configuring MDX content, setting up Tailwind styling, integrating component libraries, building interactive UI elements, or when user mentions React integration, MDX setup, Tailwind configuration, component patterns, or UI frameworks.
9allowed-tools: - Read
10 - Write
11 - Edit
12 - Bash
13 - Glob
14 - Grep
15---
16
17# Component Integration
18
19Comprehensive patterns for integrating React components, MDX content, and Tailwind CSS into Astro websites with type safety, performance optimization, and best practices.
20
21## Overview
22
23This skill provides:
24- React component integration with Astro islands architecture
25- MDX configuration for content-rich component authoring
26- Tailwind CSS setup with custom design systems
27- Type-safe component patterns with TypeScript
28- Performance optimization techniques
29- Component library integration (shadcn/ui, Radix, etc.)
30
31## Setup Scripts
32
33### Core Setup Scripts
34
351. **scripts/setup-react.sh** - Initialize React integration in Astro project
362. **scripts/setup-mdx.sh** - Configure MDX support with plugins
373. **scripts/setup-tailwind.sh** - Install and configure Tailwind CSS
384. **scripts/validate-integration.sh** - Validate component integration setup
395. **scripts/optimize-components.sh** - Apply performance optimizations
40
41### Utility Scripts
42
436. **scripts/generate-component.sh** - Scaffold new React components
447. **scripts/add-component-library.sh** - Integrate shadcn/ui or other libraries
45
46## Templates
47
48### React Component Templates
49
501. **templates/react/basic-component.tsx** - Simple React component with TypeScript
512. **templates/react/interactive-component.tsx** - Interactive component with state
523. **templates/react/island-component.tsx** - Astro island with client directives
534. **templates/react/form-component.tsx** - Form component with validation
545. **templates/react/data-fetching-component.tsx** - Component with async data
556. **templates/react/component-with-context.tsx** - Context provider pattern
56
57### MDX Templates
58
597. **templates/mdx/basic-mdx.mdx** - Basic MDX file structure
608. **templates/mdx/mdx-with-components.mdx** - MDX using custom components
619. **templates/mdx/mdx-layout.astro** - Layout wrapper for MDX content
6210. **templates/mdx/remark-plugin.js** - Custom remark plugin template
63
64### Tailwind Templates
65
6611. **templates/tailwind/tailwind.config.ts** - Full Tailwind configuration
6712. **templates/tailwind/custom-theme.ts** - Custom design system theme
6813. **templates/tailwind/base-styles.css** - Base CSS with custom utilities
6914. **templates/tailwind/component-variants.ts** - CVA variant patterns
70
71### Integration Templates
72
7315. **templates/integration/astro-config-full.ts** - Complete Astro config
7416. **templates/integration/tsconfig-components.json** - TypeScript config for components
7517. **templates/integration/package-json-deps.json** - Required dependencies
76
77## Examples
78
791. **examples/basic-integration.md** - Simple React component in Astro
802. **examples/mdx-blog-post.md** - MDX blog post with components
813. **examples/tailwind-design-system.md** - Custom Tailwind design system
824. **examples/interactive-forms.md** - Forms with validation and state
835. **examples/component-library-integration.md** - shadcn/ui setup guide
846. **examples/performance-optimization.md** - Islands architecture best practices
857. **examples/type-safe-patterns.md** - TypeScript patterns for components
86
87## Instructions
88
89### Phase 1: Initial Setup
90
911. **Assess Current Setup**
92 ```bash
93 # Check existing integrations
94 bash scripts/validate-integration.sh
95 ```
96
972. **Install Required Integrations**
98 ```bash
99 # Setup React
100 bash scripts/setup-react.sh
101
102 # Setup MDX
103 bash scripts/setup-mdx.sh
104
105 # Setup Tailwind
106 bash scripts/setup-tailwind.sh
107 ```
108
1093. **Validate Installation**
110 - Check astro.config.mjs for integrations
111 - Verify package.json dependencies
112 - Test basic component rendering
113
114### Phase 2: Component Development
115
1161. **Generate Component Structure**
117 ```bash
118 # Create new component
119 bash scripts/generate-component.sh ComponentName --type interactive
120 ```
121
1222. **Apply Templates**
123 - Use templates/react/* for React components
124 - Use templates/mdx/* for content components
125 - Use templates/tailwind/* for styling patterns
126
1273. **Implement Type Safety**
128 - Define component props interfaces
129 - Use TypeScript strict mode
130 - Export component types for consumers
131
132### Phase 3: Styling Integration
133
1341. **Configure Tailwind Theme**
135 - Read: templates/tailwind/tailwind.config.ts
136 - Customize colors, fonts, spacing
137 - Add custom utilities and variants
138
1392. **Create Component Variants**
140 - Use CVA (class-variance-authority) pattern
141 - Read: templates/tailwind/component-variants.ts
142 - Define size, color, and style variants
143
1443. **Setup Base Styles**
145 - Read: templates/tailwind/base-styles.css
146 - Add custom CSS variables
147 - Define global typography styles
148
149### Phase 4: MDX Configuration
150
1511. **Setup MDX Processing**
152 - Configure remark and rehype plugins
153 - Read: templates/mdx/remark-plugin.js
154 - Add syntax highlighting, image optimization
155
1562. **Create MDX Layouts**
157 - Read: templates/mdx/mdx-layout.astro
158 - Design consistent content layouts
159 - Add frontmatter-based customization
160
1613. **Register Custom Components**
162 - Map components to MDX elements
163 - Read: templates/mdx/mdx-with-components.mdx
164 - Enable rich content authoring
165
166### Phase 5: Performance Optimization
167
1681. **Apply Islands Architecture**
169 - Use client:* directives strategically
170 - Read: examples/performance-optimization.md
171 - Minimize client JavaScript
172
1732. **Optimize Component Loading**
174 ```bash
175 bash scripts/optimize-components.sh
176 ```
177
1783. **Implement Code Splitting**
179 - Use dynamic imports for heavy components
180 - Lazy load below-the-fold content
181 - Defer non-critical interactions
182
183### Phase 6: Component Library Integration
184
1851. **Add Component Libraries**
186 ```bash
187 # Add shadcn/ui
188 bash scripts/add-component-library.sh shadcn-ui
189 ```
190
1912. **Configure Library Theming**
192 - Integrate library tokens with Tailwind
193 - Customize component defaults
194 - Ensure consistent design language
195
1963. **Create Wrapper Components**
197 - Wrap library components for Astro compatibility
198 - Add project-specific defaults
199 - Maintain type safety
200
201## Best Practices
202
203### React Integration
204
205- **Use Islands Architecture**: Only hydrate interactive components
206- **Minimize Bundle Size**: Import only needed components
207- **Type Everything**: Use TypeScript interfaces for all props
208- **Avoid Layout Shift**: Reserve space for hydrated components
209- **Handle SSR**: Ensure components work server-side
210
211### MDX Content
212
213- **Separate Content from Logic**: Keep MDX focused on content
214- **Use Frontmatter**: Add metadata for routing and SEO
215- **Component Consistency**: Reuse components across MDX files
216- **Optimize Images**: Use Astro Image optimization
217- **Test Rendering**: Validate MDX compiles correctly
218
219### Tailwind Styling
220
221- **Design Tokens**: Define colors, spacing in config
222- **Utility Classes**: Prefer utilities over custom CSS
223- **Component Variants**: Use CVA for variant management
224- **Responsive Design**: Mobile-first approach
225- **Dark Mode**: Configure dark mode variant strategy
226
227### Performance
228
229- **Static First**: Generate static HTML by default
230- **Selective Hydration**: Use client:visible, client:idle
231- **Bundle Analysis**: Monitor JavaScript bundle sizes
232- **CSS Optimization**: Purge unused Tailwind classes
233- **Image Optimization**: Use Astro Image component
234
235## Common Patterns
236
237### Pattern 1: Interactive Island Component
238
239```tsx
240// Component with selective hydration
241import { useState } from 'react';
242
243interface Props {
244 initialCount?: number;
245}
246
247export default function Counter({ initialCount = 0 }: Props) {
248 const [count, setCount] = useState(initialCount);
249
250 return (
251 <button onClick={() => setCount(count + 1)}>
252 Count: {count}
253 </button>
254 );
255}
256```
257
258Usage in Astro:
259```astro
260---
261import Counter from '@/components/Counter';
262---
263<Counter client:visible initialCount={5} />
264```
265
266### Pattern 2: MDX with Custom Components
267
268```mdx
269---
270title: "Blog Post with Components"
271---
272import { Alert } from '@/components/Alert';
273
274# My Blog Post
275
276<Alert type="info">
277 This is custom component in MDX
278</Alert>
279```
280
281### Pattern 3: Tailwind Variant Component
282
283```tsx
284import { cva, type VariantProps } from 'class-variance-authority';
285
286const buttonVariants = cva(
287 'rounded-md font-medium transition-colors'
288 {
289 variants: {
290 variant: {
291 primary: 'bg-blue-600 text-white hover:bg-blue-700'
292 secondary: 'bg-gray-200 text-gray-900 hover:bg-gray-300'
293 }
294 size: {
295 sm: 'px-3 py-1.5 text-sm'
296 md: 'px-4 py-2 text-base'
297 lg: 'px-6 py-3 text-lg'
298 }
299 }
300 defaultVariants: {
301 variant: 'primary'
302 size: 'md'
303 }
304 }
305);
306
307type ButtonProps = VariantProps<typeof buttonVariants> & {
308 children: React.ReactNode;
309};
310
311export function Button({ variant, size, children }: ButtonProps) {
312 return (
313 <button className={buttonVariants({ variant, size })}>
314 {children}
315 </button>
316 );
317}
318```
319
320## Troubleshooting
321
322### React Components Not Hydrating
323
324**Problem**: Components render statically but don't have interactivity
325
326**Solution**:
3271. Add client directive: `client:load`, `client:visible`, or `client:idle`
3282. Ensure component is exported as default
3293. Check for SSR-incompatible code (window, document)
330
331### MDX Compilation Errors
332
333**Problem**: MDX files fail to compile
334
335**Solution**:
3361. Validate MDX syntax (closing tags, component imports)
3372. Check remark/rehype plugin compatibility
3383. Ensure imported components are available
3394. Review astro.config.mjs MDX configuration
340
341### Tailwind Classes Not Applied
342
343**Problem**: Tailwind utilities not working in components
344
345**Solution**:
3461. Check tailwind.config.ts content paths include component files
3472. Import Tailwind base styles in layout
3483. Verify PostCSS configuration
3494. Clear Astro cache: `rm -rf .astro`
350
351### Type Errors in Components
352
353**Problem**: TypeScript errors in React components
354
355**Solution**:
3561. Review templates/integration/tsconfig-components.json
3572. Ensure @types/react is installed
3583. Check jsx compiler options
3594. Validate component prop interfaces
360
361## Related Skills
362
363- **content-collections**: Use for structured content with type safety
364- **performance-optimization**: Additional performance patterns
365- **testing-patterns**: Testing React components in Astro
366
367## Requirements
368
369- Node.js 18+
370- Astro 4.0+
371- React 18+
372- Tailwind CSS 3.4+
373- TypeScript 5.0+
374
375---
376
377**Plugin**: website-builder
378**Version**: 1.0.0