Просмотр исходного кода

fully support server-side rendering

we can provide the initial comments via `initialData` now, allowing to
render the comments on the server. everything else still works, it just
fills in the comments if they were supplied.
Lucas Stadler лет назад: 11
Родитель
Сommit
915445b005
2 измененных файлов с 7 добавлено и 2 удалено
  1. 5 1
      js/react/comments.js
  2. 2 1
      js/react/static.js

+ 5 - 1
js/react/comments.js

51
export class CommentBox extends React.Component {
51
export class CommentBox extends React.Component {
52
	constructor(props) {
52
	constructor(props) {
53
		super(props);
53
		super(props);
54
		this.state = {data: []}
54
		if (props.initialData) {
55
			this.state = {data: props.initialData}
56
		} else {
57
			this.state = {data: []}
58
		}
55
59
56
		this.handleCommentSubmit = this.handleCommentSubmit.bind(this);
60
		this.handleCommentSubmit = this.handleCommentSubmit.bind(this);
57
	}
61
	}

+ 2 - 1
js/react/static.js

3
3
4
import {CommentBox} from "./comments.js";
4
import {CommentBox} from "./comments.js";
5
5
6
let commentsHtml = React.renderToString(<CommentBox url="comments.json" />);
6
let comments = JSON.parse(fs.readFileSync("comments.json"));
7
let commentsHtml = React.renderToString(<CommentBox initialData={comments} url="comments.json" />);
7
8
8
let html = `<!doctype html>
9
let html = `<!doctype html>
9
<html>
10
<html>