import Blog from './blog.mdx' and use <Blog>, TemplateDX’s bundler substitutes the imported file’s AST directly into the parent at parse time — there is no React render cycle, no hooks, no event handlers. Just template composition.
Constraints
- Only default imports are supported.
import { Thing } from './file.mdx'throws at bundle time — named imports are explicitly rejected perbundler.ts:185-196. - Imported files must be
.mdx. The bundler recognizes.mdxspecifically; other extensions aren’t inlined. - Use
{props.*}for data,{props.children}for body content. Both are populated by the bundler from the parent’s JSX attributes and child nodes. - No React runtime. Hooks, event handlers, refs — none of these do anything inside a TemplateDX component. If you find yourself reaching for them, you probably want a custom tag plugin instead.
Example
Givenblog.mdx:
blog.mdx
index.mdx
<Blog> tag is replaced with the contents of blog.mdx, with props.title resolved to "Turtles" and props.children resolved to the child body.
When to use a component vs. a tag
- Components — for static template fragments you want to compose. Think partials: a shared
<SystemPrompt>header, a reusable<FewShotExamples>block. - Tags — for logic that needs runtime behavior: conditional rendering (
<If>), iteration (<ForEach>), raw passthrough (<Raw>), or custom extensions you implement as aTagPlugin.