marp-team / marp-react

[INACTIVE] Marp renderer component for React
https://marp-react.netlify.com/
MIT License
19 stars 3 forks source link

Add components or props to render a single slide (feature request) #30

Closed reminjp closed 4 years ago

reminjp commented 4 years ago

I am so grateful for this package.

I want to render only a single slide efficiently (e.g. only the first slide to preview the content). How about adding new components or props which skip unnecessary parse() and renderToReact()?

yhatt commented 4 years ago

We think there is not a need for that. You can already skip unnecessary rendering by using custom renderer:

const markdown = `
# foo

---

# bar
`

// Render only first slide
ReactDOM.render(
  <Marp
    markdown={markdown}
    render={([firstSlide]) => firstSlide.slide}
  />,
  document.getElementById('preview')
)
reminjp commented 4 years ago

Right, but I was just a little bothered by the process of building components for all slides. I also understand that the current API design is simple and general-purpose...

yhatt commented 4 years ago

You are taking it too seriously. Just creating VDOM through createElement in internal renderToReact() won't expect to make slow. The almost of performance hit is lead by rendering DOM actually.

yhatt commented 4 years ago

If you REALLY want to render single page with no extra HTML parsing, the best solution is using Marp Core directly in React. See also our source code of marp-team/marp: https://github.com/marp-team/marp/blob/master/packages/website/src/components/marp.js.jsx#L42

Marp React is designed for easy to begin rendering Marp in a lot of use cases, and should create your own component if you want to take the advance.