Home > Back-end >  React parse text to html markup
React parse text to html markup

Time:08-29

I use React JS, and I want to make a universal component, to show message for user. Like as at image: enter image description here

I want to send text like as this : "Lorem ipsum ["Link"](url) Lorem ipsum **Strong text**". How I may parse this with JavaScript? I can imagine how to implement this, but I would not like to reinvent my wheel, maybe there are some ready-made and elegant solutions?

CodePudding user response:

What you need is a Markdown component for React. Try react-markdown:

import React from 'react';
import ReactDom from 'react-dom';
import ReactMarkdown from 'react-markdown';
ReactDom.render(
    <ReactMarkdown>
        Lorem ipsum [link](url) <br />
        Lorem ipsum **Strong text**
    </ReactMarkdown>,
    yourElement
)
  • Related