react-markdown
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|---|---|---|---|---|
@types/hast | 2.3.10 | 2.38 kB | MIT | prod | |
@types/prop-types | 15.7.12 | 6.55 kB | MIT | prod | |
@types/react | 18.3.1 | 427.28 kB | MIT | prod peer | |
@types/unist | 2.0.10 | 2.5 kB | MIT | prod | |
comma-separated-tokens | 2.0.3 | 3.73 kB | MIT | prod | |
hast-util-whitespace | 2.0.1 | 3.95 kB | MIT | prod | |
prop-types | 15.8.1 | 22.12 kB | MIT | prod | |
property-information | 6.5.0 | 102.37 kB | MIT | prod | |
react-is | 18.3.1 | 23.45 kB | MIT | prod | |
react | 18.3.1 | 310.65 kB | MIT | prod peer | |
remark-parse | 10.0.2 | 5.75 kB | MIT | prod | |
remark-rehype | 10.1.0 | 8.52 kB | MIT | prod | |
space-separated-tokens | 2.0.2 | 3.14 kB | MIT | prod | |
style-to-object | 0.4.4 | 10.42 kB | MIT | prod | |
unified | 10.1.2 | 20 kB | MIT | prod | |
unist-util-visit | 4.1.2 | 6.4 kB | MIT | prod | |
vfile | 5.3.7 | 17.89 kB | MIT | prod |
React-Markdown is a highly popular npm package designed to render markdown in your React applications. Its primary functionality revolves around accepting markdown strings and converting them into a virtual DOM, thereby allowing you to render the parsed markdown as React elements. Not only is React-Markdown safe by default (preventing dangerouslySetInnerHTML
or XSS attacks), but it also supports components and plugins, providing an efficient and secure way to incorporate markdown rendering into your development projects.
To use React-Markdown, you first need to install the package into your project using npm. The command for this is npm install react-markdown
. Once you've successfully installed React-Markdown, you'll need to add a simple import statement: import Markdown from 'react-markdown';
at the beginning of your file to access its features.
For a basic usage example, suppose you have a markdown string like const markdown = '# Hi, *Pluto*!';
. To render this string as markdown, pass it within the React-Markdown component in your render method like so:
import React from 'react';
import ReactDom from 'react-dom';
import Markdown from 'react-markdown';
const markdown = '# Hi, *Pluto*!';
ReactDom.render(<Markdown>{markdown}</Markdown>, document.body);
This will render a headline saying "Hi, Pluto!" in italics as interpreted from the markdown string. For more advanced use cases involving plugins and custom components, refer to the extensive examples provided in the React-Markdown's GitHub repository readme section.
The extensive documentation for React-Markdown can be found on its GitHub repository. The readme file on this repository includes everything you need to get started, including installation instructions, basic and advanced usage examples, plugin information, and API details. Also, it explains security measures and how to use React-Markdown with JSX.