question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

previewRender should allow a react component as return value

See original GitHub issue

Hello, I tried to integrate this in a project where we use react-markdown and would like to use the ReactMarkdown Component in previewRender to keep preview and live rendering consistent - sadly previewRender expects a string as far as i can see. So sth like:

<SimpleMDE
          value={this.state.text}
          onChange={this.setText}
          options={{
            previewRender (text) {
              return <ReactMarkdown
                source={text}
                renderers={{
                  CodeBlock: CodeRenderer,
                  Code: CodeRenderer
                }}
              />
            }
          }}
        />

is currently not possible.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:2
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
RIP21commented, Jun 25, 2018

@btzr-io Just tested it. WORKS PERFECTLY 😄

import ReactDOMServer from "react-dom/server";

<SimpleMDEReact
          label="Markdown Editor"
          value={this.state.textValue1}
          onChange={this.handleChange1}
          options={{
            previewRender(plainText) {
              return ReactDOMServer.renderToString(<div>LOL</div>);
            }
          }}
        />

Giving me perfect LOL in the preview 😄

@ningappa use code above to solve your issue 😃

Will update Readme.md now.

1reaction
RIP21commented, Jun 25, 2018

@btzr-io 😄 Should work tho.

@ningappa Make JSX in the preview seems impossible for me. We just expose here an option object here that basically create a new instance of SimpleMDE that we make controllable using React, we are unable to intervene into the previewRenderer here to make it JSX controllable. I will dig into the docs of SimpleMDE now but I’m not sure whether it’s possible. A workaround of @btzr-io looks good, not sure about the performance of such tho, and whether this function works on non-Node.js environment but web 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Components and Props - React
Components let you split the UI into independent, reusable pieces, and think about each piece in isolation. This page provides an introduction to...
Read more >
Should a component's render method have return type React ...
createElement and is narrow in scope whereas React.ReactNode is more broad and covers all possible values that a Component could return.
Read more >
Return a Variable in the Render Function in React | Pluralsight
Thus, the JSX elements can also get returned to the variable, and that variable can be used for rendering. For an example demonstration,...
Read more >
React Class Components - W3Schools
When creating a React component, the component's name must start with an upper ... The component also requires a render() method, this method...
Read more >
How to use Props in React - Robin Wieruch
A bit later you will split out your first React function component: import * as React from 'react';. const App = () =>...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found