React Components
Learn how to use React components
Create interactive examples and dynamic content in your documentation using familiar React hooks.
No imports needed! All standard React hooks are automatically available in your MDX files.
Available Hooks
You can use all standard React hooks in your documentation, such as useState
, useEffect
, and other React hooks.
Interactive Examples
Creating Components Directly in MDX
Create a component directly in your MDX file using React hooks to build interactive elements that respond to user actions:
A basic counter component created with useState
hook
Importing Components from Snippet Files
Import snippets into your MDX files to create reusable interactive components. Store snippets in the snippets
folder for better organization. Learn more in the reusable snippets documentation.
Interactive HSL color generator created with multiple React hooks
Using React Hooks
Create a snippet file
Create a new file in the snippets
folder with your component code.
Import the snippet
Add an import statement at the top of your MDX file:
Use the component
Add the component to your MDX content wherever needed:
Important Considerations
Client-Side Rendering Impact
Client-Side Rendering Impact
React hook components render on the client-side, which has several implications:
- SEO: Search engines might not fully index dynamic content
- Initial Load: Visitors may experience a flash of loading content before components render
- Accessibility: Ensure dynamic content changes are announced to screen readers
Performance Best Practices
Performance Best Practices
- Optimize Dependency Arrays: Include only necessary dependencies in your
useEffect
dependency arrays - Memoize Complex Calculations: Use
useMemo
oruseCallback
for expensive operations - Reduce Re-renders: Break large components into smaller ones to prevent cascading re-renders
- Lazy Loading: Consider lazy loading complex components to improve initial page load time