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.
  • No external npm packages: You cannot import third-party packages (for example, lodash, axios, date-fns). 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.
  • No cross-snippet imports: Snippet files cannot import other snippet files. Import all dependencies directly in the parent MDX file.
  • 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 must be in the /snippets/ folder. Learn more about reusable snippets.
Nested imports are not supported. Import all referenced components directly into the parent MDX file.
Create a component file in snippets/:
/snippets/color-generator.jsx
Then import and use it:

Considerations

  • SEO: Search engines may not fully index client-rendered dynamic content.
  • Initial load: Visitors may see a flash before components render.
  • 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.