ここにコードがあります
componentDidMount: function () {
var self = this,
templates;
new Promise(function (resolve, reject) {
API.getTemplates(function (err, result) {
if (!err) {
templates = result.templates;
resolve();
}
});
}).then(function () {
return new Promise(function (resolve, reject) {
_.map(templates,function (template) {
console.log("template.companyId " +template.companyId);
API.getCompanyById(template.companyId, function (err, result) {
if (!err) {
template.userId = result.company.userId;
resolve();
}
})
});
});
}).then(function(){
console.log("templates");
console.log(templates);
self.setState({templates: templates});
});
},
クロム反応ツールでは、状態は正しいです。render メソッドで this.state.templates を呼び出しています。ただし、デフォルトでは null です
getInitialState: function () {
return {templates: null}
},
setState の実行後に rerender が呼び出されていないようです。また、別のルートに進むと、このコンポーネントの状態は保存されず、template:null になります。