Skip to content

Commit

Permalink
Add note on performance of evaluate
Browse files Browse the repository at this point in the history
Closes GH-1655.
  • Loading branch information
wooorm committed Oct 20, 2021
1 parent d636735 commit b3e64dc
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions packages/mdx/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -737,6 +737,22 @@ console.log(await evaluate(file, {...runtime}))

</details>

###### Note: Performance

Compiling (and running) MDX takes time.
If you’re live-rendering a string of MDX that often changes using a virtual DOM
based framework (such as React), one performance improvement is to call the
`MDXContent` component yourself.
The reason is that the `evaluate` creates a new function each time, which cannot
be diffed:

```diff
const {default: MDXContent} = await evaluate('…')

-<MDXContent {...props} />
+MDXContent(props)
```

### `evaluateSync(file, options)`

Compile and run MDX.
Expand Down

0 comments on commit b3e64dc

Please sign in to comment.