Skip to content

Commit a1e1c3f

Browse files
committed
Update docs
1 parent aeee9ac commit a1e1c3f

File tree

1 file changed

+56
-37
lines changed

1 file changed

+56
-37
lines changed

readme.md

+56-37
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ A basic hello world:
3737
```jsx
3838
import React from 'react'
3939
import ReactMarkdown from 'react-markdown'
40-
import {render} from 'react-dom'
40+
import ReactDom from 'react-dom'
4141

42-
render(<ReactMarkdown># Hello, *world*!</ReactMarkdown>, document.body)
42+
ReactDom.render(<ReactMarkdown># Hello, *world*!</ReactMarkdown>, document.body)
4343
```
4444

4545
<details>
@@ -53,19 +53,22 @@ render(<ReactMarkdown># Hello, *world*!</ReactMarkdown>, document.body)
5353

5454
</details>
5555

56-
Here is an example using `require`s, passing the markdown as a string, and how
56+
Here is an example that shows passing the markdown as a string and how
5757
to use a plugin ([`remark-gfm`][gfm], which adds support for strikethrough,
5858
tables, tasklists and URLs directly):
5959

6060
```jsx
61-
const React = require('react')
62-
const ReactMarkdown = require('react-markdown')
63-
const render = require('react-dom').render
64-
const gfm = require('remark-gfm')
61+
import React from 'react'
62+
import ReactDom from 'react-dom'
63+
import ReactMarkdown from 'react-markdown'
64+
import remarkGfm from 'remark-gfm'
6565

6666
const markdown = `Just a link: https://reactjs.com.`
6767

68-
render(<ReactMarkdown remarkPlugins={[gfm]} children={markdown} />, document.body)
68+
ReactDom.render(
69+
<ReactMarkdown children={markdown} remarkPlugins={[remarkGfm]} />,
70+
document.body
71+
)
6972
```
7073

7174
<details>
@@ -144,8 +147,8 @@ strikethrough, tables, tasklists and URLs directly:
144147
```jsx
145148
import React from 'react'
146149
import ReactMarkdown from 'react-markdown'
147-
import {render} from 'react-dom'
148-
import gfm from 'remark-gfm'
150+
import ReactDom from 'react-dom'
151+
import remarkGfm from 'remark-gfm'
149152

150153
const markdown = `A paragraph with *emphasis* and **strong importance**.
151154
@@ -161,7 +164,10 @@ A table:
161164
| - | - |
162165
`
163166

164-
render(<ReactMarkdown remarkPlugins={[gfm]} children={markdown} />, document.body)
167+
ReactDom.render(
168+
<ReactMarkdown children={markdown} remarkPlugins={[remarkGfm]} />,
169+
document.body
170+
)
165171
```
166172

167173
<details>
@@ -211,11 +217,11 @@ second.
211217
```jsx
212218
import React from 'react'
213219
import ReactMarkdown from 'react-markdown'
214-
import {render} from 'react-dom'
215-
import gfm from 'remark-gfm'
220+
import ReactDom from 'react-dom'
221+
import remarkGfm from 'remark-gfm'
216222

217-
render(
218-
<ReactMarkdown remarkPlugins={[[gfm, {singleTilde: false}]]}>
223+
ReactDom.render(
224+
<ReactMarkdown remarkPlugins={[[remarkGfm, {singleTilde: false}]]}>
219225
This ~is not~ strikethrough, but ~~this is~~!
220226
</ReactMarkdown>,
221227
document.body
@@ -243,24 +249,10 @@ In this case, we apply syntax highlighting with the seriously super amazing
243249

244250
```jsx
245251
import React from 'react'
252+
import ReactDom from 'react-dom'
246253
import ReactMarkdown from 'react-markdown'
247254
import {Prism as SyntaxHighlighter} from 'react-syntax-highlighter'
248-
/* Use `…/dist/cjs/…` if you’re not in ESM! */
249255
import {dark} from 'react-syntax-highlighter/dist/esm/styles/prism'
250-
import {render} from 'react-dom'
251-
252-
const components = {
253-
code({node, inline, className, children, ...props}) {
254-
const match = /language-(\w+)/.exec(className || '')
255-
return !inline && match ? (
256-
<SyntaxHighlighter style={dark} language={match[1]} PreTag="div" children={String(children).replace(/\n$/, '')} {...props} />
257-
) : (
258-
<code className={className} {...props}>
259-
{children}
260-
</code>
261-
)
262-
}
263-
}
264256

265257
// Did you know you can use tildes instead of backticks for code in markdown? ✨
266258
const markdown = `Here is some JavaScript code:
@@ -270,7 +262,30 @@ console.log('It works!')
270262
~~~
271263
`
272264

273-
render(<ReactMarkdown components={components} children={markdown} />, document.body)
265+
ReactDom.render(
266+
<ReactMarkdown
267+
children={markdown}
268+
components={{
269+
code({node, inline, className, children, ...props}) {
270+
const match = /language-(\w+)/.exec(className || '')
271+
return !inline && match ? (
272+
<SyntaxHighlighter
273+
children={String(children).replace(/\n$/, '')}
274+
style={dark}
275+
language={match[1]}
276+
PreTag="div"
277+
{...props}
278+
/>
279+
) : (
280+
<code className={className} {...props}>
281+
{children}
282+
</code>
283+
)
284+
}
285+
}}
286+
/>,
287+
document.body
288+
)
274289
```
275290

276291
<details>
@@ -295,17 +310,18 @@ is used to support math in markdown, and a transform plugin
295310

296311
```jsx
297312
import React from 'react'
298-
import {render} from 'react-dom'
313+
import ReactDom from 'react-dom'
299314
import ReactMarkdown from 'react-markdown'
300315
import remarkMath from 'remark-math'
301316
import rehypeKatex from 'rehype-katex'
317+
302318
import 'katex/dist/katex.min.css' // `rehype-katex` does not import the CSS for you
303319

304-
render(
320+
ReactDom.render(
305321
<ReactMarkdown
322+
children={`The lift coefficient ($C_L$) is a dimensionless coefficient.`}
306323
remarkPlugins={[remarkMath]}
307324
rehypePlugins={[rehypeKatex]}
308-
children={`The lift coefficient ($C_L$) is a dimensionless coefficient.`}
309325
/>,
310326
document.body
311327
)
@@ -374,17 +390,20 @@ can spare the bundle size (±60kb minzipped), then you can use
374390

375391
```jsx
376392
import React from 'react'
393+
import ReactDom from 'react-dom'
377394
import ReactMarkdown from 'react-markdown'
378395
import rehypeRaw from 'rehype-raw'
379-
import {render} from 'react-dom'
380396

381397
const input = `<div class="note">
382398
383399
Some *emphasis* and <strong>strong</strong>!
384400
385401
</div>`
386402

387-
render(<ReactMarkdown rehypePlugins={[rehypeRaw]} children={input} />, document.body)
403+
ReactDom.render(
404+
<ReactMarkdown rehypePlugins={[rehypeRaw]} children={input} />,
405+
document.body
406+
)
388407
```
389408

390409
<details>
@@ -408,7 +427,7 @@ markdown!
408427
You can also change the things that come from markdown:
409428

410429
```js
411-
<Markdown
430+
<ReactMarkdown
412431
components={{
413432
// Map `h1` (`# heading`) to use `h2`s.
414433
h1: 'h2',

0 commit comments

Comments
 (0)