初学react,在学习服务端渲染,用的isomorphic-fetch这个package。
`
componentWillMount() {
console.log("in componentWillMount");
let THIS = this;
fetch('/build/msg.json').then(function(res){
if (res.ok) {
res.json().then(function(data) {
console.log(data.message);
THIS.state = {message: data.message};
});
}
}, function(e){
console.log("error", e)
});
console.log("in componentWillMount End");
}
`
我是这样做的,但是在fetch结果返回之前,页面就渲染完了。
请问正确的写法是什么,搜索了半天也没学明白,才来发帖