Your first markdown view and editor
With the package installed, let's put both components on the screen: EnrichedMarkdownText to display rich text and EnrichedMarkdownTextInput to edit it. By the end of this page you'll have rendered your first Markdown and built a minimal editor with a working toolbar button.
Rendering Markdown
EnrichedMarkdownText is a read-only component. You give it a Markdown string through the markdown prop and it renders fully native text - no WebView involved.
That is all a display needs. The onLinkPress callback fires when the reader taps a link - here we hand the URL off to React Native's Linking so it opens in the browser.
You can restyle every element through the markdownStyle prop - see the Style properties reference for the full list.
defaultMarkdownStyle is a docs helper, not part of the library: it gives every example on this site a complete light/dark palette in one line. In your own app, pass your own markdownStyle object or omit the prop entirely to get the built-in defaults.
Building an editor
EnrichedMarkdownTextInput is the writing side. It's an uncontrolled input. It doesn't hold its value in React state or props, but talks to the native text view directly. That keeps it fast, but it means you drive formatting imperatively through a ref rather than by passing a value down.
Here's a minimal editor with a single toolbar button that toggles bold and reflects whether bold is currently active:
Two things are worth calling out, because every editor feature follows the same two patterns:
- You apply formatting by calling methods on the ref. The ref is typed as
EnrichedMarkdownTextInputInstance. Pressing the button callsref.current?.toggleBold(), which toggles bold across the current selection - or arms it for the next characters you type when there's no selection. - You read formatting from the
onChangeStatecallback. Its payload has one entry per style (bold,italic, and so on), each with anisActiveflag. That's what lets the button know whether to say "Bold" or "Unbold" and change color.
The same toggle / onChangeState pair drives italic, underline, strikethrough and more - so extending the toolbar is mostly repeating this shape. The input also ships a native format bar on selection out of the box, so basic formatting works even before you build any UI. See the EnrichedMarkdownTextInput reference for the full set of methods and events.
How the two fit together
The mental model to carry into the rest of the docs: Markdown is the shared source of truth between the two components.
EnrichedMarkdownTextInputedits Markdown. Seed it with a Markdown string (defaultValue) and read the edited content back as Markdown at any time (onChangeMarkdown, orgetMarkdown()on the ref - it returns aPromise<string>).EnrichedMarkdownTextrenders Markdown through itsmarkdownprop.
Because both sides speak the same format, content flows between them without conversion - edit in one, store the Markdown, render it in the other.
onChangeMarkdown serializes on every change, which isn't free. If you don't need the Markdown string, leave the callback off and the input skips serialization entirely.
Next steps
You now have a working display and editor and the model that ties them together. From here:
- Core concepts - the ideas behind the two components.
- Feature support - what's supported and how to enable it.