Skip to main content
Build interactive elements in your docs using React components and hooks directly in MDX files.

Inline components

Declare components directly in your MDX file:

Constraints

React components in Mintlify run in a sandboxed MDX environment with the following constraints:
  • React hooks are pre-injected: useState, useEffect, useRef, useCallback, useMemo, useContext, and useReducer are available without importing them.
  • npm packages require setup: To import third-party packages, set up third-party libraries. Otherwise, use browser built-ins or write the logic inline.
  • No default exports: Use named exports (export const MyComponent = ...). Default exports (export default) are not supported.
  • Each file declares its own imports: If a snippet uses another snippet, import it in that snippet file. Imports on the page don’t apply to the snippets the page imports. See Nested snippets.
  • No JSON imports: Importing .json files is not supported.
  • No code splitting: React.lazy and dynamic import() are not supported. All component code on a page, including imported snippets, compiles into the page and loads with it.

Import components

Component files are .jsx or .tsx files, and you can place them anywhere in your project. Learn more about reusable snippets. Create a component file in snippets/:
/snippets/color-generator.jsx
Then import and use it:

Considerations

  • Client-side rendering: Most custom components render in the browser after the page loads, so they aren’t in the server-rendered HTML. This applies to components you import by name from a snippet, such as import { ColorGenerator } from "/snippets/color-generator.jsx", and to most components you define with export in an MDX file. MDX snippets that you import as content, such as import MySnippet from "/snippets/my-snippet.mdx", render on the server. A component you define with export also renders on the server when it is a simple template. It must only place its props into HTML elements and built-in components, without state, hooks, function calls, conditionals, event handlers, or style attributes. Every place you use it must pass only plain string attributes, such as <HeroCard title="Quickstart" href="/quickstart" />.
  • SEO: Because custom components are not in the initial HTML, search engines may not fully index their content.
  • Initial load: Visitors may see a flash or layout shift while custom components render. For content that must appear in the initial HTML or must not shift on load, use built-in components such as cards and columns instead. Most built-in components render on the server.
  • Accessibility: Ensure screen readers announce dynamic content changes.
  • Optimize dependency arrays: Only include necessary dependencies in useEffect.
  • Memoize expensive operations: Use useMemo or useCallback where appropriate.
  • Reduce re-renders: Break large components into smaller ones.
  • Lazy loading: Component code cannot lazy load. All components load with the page. If a component performs resource-intensive operations when it mounts, such as fetching data or heavy computation, use conditional rendering to defer mounting it until user interaction.