比如这个例子:
let initialState = {
books: null,
readers: null
};
let TestComponent = React.createClass({
getInitialState: function() {
return initialState;
}
componentDidMount: function() {
$.get("/api/books").then(/*这里设置 state: books*/);
$.get("/api/readers").then(/*这里设置 state: readers*/);
}
});
因为 react 的 checksum 是根据 initialState 来计算的,所以第 1 、 2 种方式中修改 initialState 后,会引起 checksum 不一致,错误类似于这样:
Warning: React attempted to reuse markup in a container but the checksum was invalid. This generally means that you are using server rendering and the markup generated on the server was not what the client was expecting. React injected new markup to compensate which works but you have lost many of the benefits of server rendering. Instead, figure out why the markup being generated is different on the client or server:
所以好像是行不通的。
我的问题是,像 1 、 2 这种程度(会加载数据)的方法是怎么实现的?还是说 react server rendering 就是指像 3 这样(不会加载数据)?
比如这个帖子( https://www.v2ex.com/t/203001 )说的好像是“会加载数据”的哪种。