W
W
wqqe2021-06-28 05:48:35
React
wqqe, 2021-06-28 05:48:35

How to get string from React component?

Let's say I have a component

const Main = () => {
  return (
    <div className='main'>
      <div style={{ backgroundColor: 'red' }}>
        <h1 className='main__header'>Hello world</h1>
      </div>
      <button type='button' onClick={handleClick}>
        press me
      </button>
    </div>
  )
}

I need a parser that would accept <Main/>something like this:
someToParser( <Main/>, additional options)
and return a string:
"<div className='main'>
      <div style={{ backgroundColor: 'red' }}>
        <h1 className='main__header'>Hello world</h1>
      </div>
      <button type='button' onClick={handleClick}>
        press me
      </button>
    </div>"

It's the string, not the html, that's important.
I've searched all over the Internet and haven't found anything that could help me.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
ParaBellum577, 2021-06-28
@ParaBellum577

Here is what you are looking for https://ru.reactjs.org/docs/react-dom-server.html

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question