Skip to content

Commit

Permalink
Refactor docs to use createRoot
Browse files Browse the repository at this point in the history
Closes GH-779.

Co-authored-by: tris203 <[email protected]>
  • Loading branch information
wooorm and tris203 committed Nov 6, 2023
1 parent 2245c64 commit 55d8d83
Showing 1 changed file with 22 additions and 28 deletions.
50 changes: 22 additions & 28 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,12 @@ A basic hello world:

```jsx
import React from 'react'
import ReactDom from 'react-dom'
import {createRoot} from 'react-dom/client'
import Markdown from 'react-markdown'

const markdown = '# Hi, *Pluto*!'

ReactDom.render(<Markdown>{markdown}</Markdown>, document.body)
createRoot(document.body).render(<Markdown>{markdown}</Markdown>)
```

<details>
Expand All @@ -142,15 +142,14 @@ directly):

```jsx
import React from 'react'
import ReactDom from 'react-dom'
import {createRoot} from 'react-dom/client'
import Markdown from 'react-markdown'
import remarkGfm from 'remark-gfm'

const markdown = `Just a link: www.nasa.gov.`

ReactDom.render(
<Markdown remarkPlugins={[remarkGfm]}>{markdown}</Markdown>,
document.body
createRoot(document.body).render(
<Markdown remarkPlugins={[remarkGfm]}>{markdown}</Markdown>
)
```

Expand Down Expand Up @@ -308,7 +307,7 @@ tables, tasklists and URLs directly:
```jsx
import React from 'react'
import ReactDom from 'react-dom'
import {createRoot} from 'react-dom/client'
import Markdown from 'react-markdown'
import remarkGfm from 'remark-gfm'

Expand All @@ -326,9 +325,8 @@ A table:
| - | - |
`

ReactDom.render(
<Markdown remarkPlugins={[remarkGfm]}>{markdown}</Markdown>,
document.body
createRoot(document.body).render(
<Markdown remarkPlugins={[remarkGfm]}>{markdown}</Markdown>
)
```

Expand Down Expand Up @@ -379,17 +377,16 @@ strikethrough:
```jsx
import React from 'react'
import ReactDom from 'react-dom'
import {createRoot} from 'react-dom/client'
import Markdown from 'react-markdown'
import remarkGfm from 'remark-gfm'

const markdown = 'This ~is not~ strikethrough, but ~~this is~~!'

ReactDom.render(
createRoot(document.body).render(
<Markdown remarkPlugins={[[remarkGfm, {singleTilde: false}]]}>
{markdown}
</Markdown>,
document.body
</Markdown>
)
```

Expand All @@ -416,7 +413,7 @@ In this case, we apply syntax highlighting with the seriously super amazing

```jsx
import React from 'react'
import ReactDom from 'react-dom'
import {createRoot} from 'react-dom/client'
import Markdown from 'react-markdown'
import {Prism as SyntaxHighlighter} from 'react-syntax-highlighter'
import {dark} from 'react-syntax-highlighter/dist/esm/styles/prism'
Expand All @@ -429,7 +426,7 @@ console.log('It works!')
~~~
`
ReactDom.render(
createRoot(document.body).render(
<Markdown
children={markdown}
components={{
Expand All @@ -439,10 +436,10 @@ ReactDom.render(
return match ? (
<SyntaxHighlighter
{...rest}
PreTag="div"
children={String(children).replace(/\n$/, '')}
style={dark}
language={match[1]}
PreTag="div"
style={dark}
/>
) : (
<code {...rest} className={className}>
Expand All @@ -451,8 +448,7 @@ ReactDom.render(
)
}
}}
/>,
document.body
/>
)
```

Expand All @@ -478,19 +474,18 @@ is used to support math in markdown, and a transform plugin

```jsx
import React from 'react'
import ReactDom from 'react-dom'
import {createRoot} from 'react-dom/client'
import Markdown from 'react-markdown'
import rehypeKatex from 'rehype-katex'
import remarkMath from 'remark-math'
import 'katex/dist/katex.min.css' // `rehype-katex` does not import the CSS for you

const markdown = `The lift coefficient ($C_L$) is a dimensionless coefficient.`

ReactDom.render(
createRoot(document.body).render(
<Markdown remarkPlugins={[remarkMath]} rehypePlugins={[rehypeKatex]}>
{markdown}
</Markdown>,
document.body
</Markdown>
)
```

Expand Down Expand Up @@ -602,7 +597,7 @@ can spare the bundle size (±60kb minzipped), then you can use
```jsx
import React from 'react'
import ReactDom from 'react-dom'
import {createRoot} from 'react-dom/client'
import Markdown from 'react-markdown'
import rehypeRaw from 'rehype-raw'

Expand All @@ -612,9 +607,8 @@ Some *emphasis* and <strong>strong</strong>!
</div>`

ReactDom.render(
<Markdown rehypePlugins={[rehypeRaw]}>{markdown}</Markdown>,
document.body
createRoot(document.body).render(
<Markdown rehypePlugins={[rehypeRaw]}>{markdown}</Markdown>
)
```

Expand Down

0 comments on commit 55d8d83

Please sign in to comment.