Преглед на файлове

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 години
родител
ревизия
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,7 +51,11 @@ export class CommentList extends React.Component {
51 51
export class CommentBox extends React.Component {
52 52
	constructor(props) {
53 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 60
		this.handleCommentSubmit = this.handleCommentSubmit.bind(this);
57 61
	}

+ 2 - 1
js/react/static.js

@ -3,7 +3,8 @@ import React from "react";
3 3
4 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 9
let html = `<!doctype html>
9 10
<html>