javascript - How to convert JSX to String? -
here jsx scode sample:
export default class element extends react.component { render() { return ( <div> <div classname="alert alert-success"> {this.props.langs.map((lang, i) => <span key={i} classname="label label-default">{lang}</span>)} </div> </div> ) } }
how string this?
<div><div classname="alert alert-success">{this.props.langs.map((lang, i) => <span key={i} classname="label label-default">{lang}</span>)}</div></div>
upd: got react components render on server. want them strings transform them templating library on client side.
just call rendertostaticmarkup()
, should static html markup language generated react.
somewhat this:
import reactdomserver 'react-dom/server'; import element './path/to/element/class'; const element = <element />; reactdomserver.rendertostaticmarkup(element)
here more docs this:
https://facebook.github.io/react/docs/react-dom-server.html#rendertostaticmarkup
Comments
Post a Comment