M
M
Memedia2017-10-03 21:20:35
JavaScript
Memedia, 2017-10-03 21:20:35

How to render React on the server?

The task is to get html on the server side from React components.
Stumbled with babel.
In general, in all examples, all templates are written without quotes. I am also getting an error. I understand that babel is needed.
Connected.

var code = 'export default React.createClass({
  getInitialState() {
    return { num: this.getRandomNumber() };
  },

  getRandomNumber(): number {
    return Math.ceil(Math.random() * 6);
  },

  render(): any {
    return <div>
      Your dice roll:
      {this.state.num}
    </div>;
  }
});';

var qwerty = babel.transform(code, {
  presets: [
    "es2015",
    "react",
    "stage-0"
  ]
});
console.info(qwerty);

I'm getting a burst of data. I need pure html to be output.
Well, I need to display it in the browser. The task is to save html to a file.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Mikhail Osher, 2017-10-03
@miraage

I highly recommend improving your Google skills.
https://github.com/zeit/next.js/

D
dvig8xi, 2017-10-03
@dvig8xi

Is https://www.gatsbyjs.org/ okay?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question