Basic Usage
There are two ways to use the library: the source component for direct rendering, and the explicit pipeline that separates parsing, preparation, and rendering for servers, caches, workers, and async work. See How it works for how the outputs and entries relate.
Source component
Wikitext performs the following synchronously:
- Parses the source with
parseWikitextor the suppliedparser. - Clones the semantic tree, runs plugins, generates HAST, and sanitizes it with
prepareWikitext. - Renders with
WikitextView.
It memoizes parsing and preparation with [parser, source, parseOptions] and [document, prepareOptions]. Inline option objects cause a reparse on every render; keep options stable or wrap them in useMemo.
The root entry only uses the synchronous prepare path. Async plugins in wikitextPlugins / rehypePlugins make Wikitext throw ASYNC_PLUGIN_IN_SYNC_PATH. Use the explicit pipeline for async plugins.
Explicit pipeline
Parsing and preparation can happen outside React. prepareWikitext does not modify the original parse snapshot; plugins run on a cloned semantic tree.
Create the parser once at module scope and reuse it. Its config is fixed at creation; changing site config requires a new parser:
Reusing prepared output
Preparation reruns plugins, HAST conversion, and sanitization. When only presentation components change, reuse the existing render snapshot:
- A parse cache key should include the source,
pageName, and site config. - A render cache key also includes resolvers, plugins,
policy,labels, andheadingIdStrategy. - Caching and invalidation are covered in Performance and budgets.
Async plugins
The synchronous entry rejects async plugins. Use prepareWikitextAsync when a transformation is asynchronous:
Preparation must finish before React renders; WikitextView never waits for a Promise. For server scenarios, see Server rendering.
Component overrides
Wikitext and WikitextView accept components (by HTML tag) and semanticComponents (by wiki semantic type). Overrides are trusted code and are the right place to integrate a design system:
This quote uses a custom component.Infobox
See the React component API for the full mapping and props; styling, labels, and heading anchors are in Styling and components.
Working with AI
This docs site is built with llms support: besides the copy-Markdown and open-in-ChatGPT/Claude entries under each page title, two plain-text files for LLMs are published alongside the site on every build:
- llms.txt: an index file with descriptions and links for every page on the site
- llms-full.txt: the entire English site content merged into one file
The Chinese site publishes the same files under /zh/: /zh/llms.txt and /zh/llms-full.txt. When citing a single page, appending .md to its URL also gives you the plain-Markdown version of that page.
Copy whichever link fits your use case and hand it to your agent.
Related
- Server rendering: server preparation, serialization, Next.js, and hydration.
- Performance and budgets: budgets, workers, and caching.
- Troubleshooting:
ASYNC_PLUGIN_IN_SYNC_PATHand other common errors.