1
私のクラスにCompondentDidMountを追加しようとしています。CompondentDidMountが失敗しましたpropType-フェッチをvarとして定義します
失敗しましたpropType:IndexRoute
に供給無効な小道具component
ただし、これはエラーを返します。
var PHOTODATA = [{ ... *json data* ... }]
...
var PhotoGallery = React.createClass({
getInitialState: function() {
return {
displayedCategories: []
};
},
...
render: function(){
var uniqueCategories = PHOTODATA.map(function (photo) {
return photo.tag; // tag is a list of tags...
}).reduce(function (uniqueList, someTags) {
return uniqueList.concat(
someTags.filter(function (thisTag) {
return !uniqueList.some(function(uniqueTag) {
return uniqueTag.id === thisTag.id && uniqueTag.taglevel === thisTag.taglevel
});
})
);
}, []
);
完全なコードは、このです:手動でこのようなVARとしての私のJSONデータを設定している場合
またvar PhotoGallery = React.createClass({
componentDidMount() {
return fetch("http://localhost:8000/api/test/?format=json")
.then((response) => response.json())
.then((json) => {
console.log(json);
this.setState({PHOTODATA: json})
})
},
getInitialState: function() {
return {
displayedCategories: []
};
},
、私のコードは正常に動作します:ここで
はComponentDidMount使用する私の試みですコード:
http://codepen.io/yarnball/pen/GqbyWr?
あなたは私たちにどのようにあなたのコードを表示することができますあなたのコンポーネント「PhotoGallery」をエクスポートしていて、他のコンポーネントがあればそれを含んでいますか? –
うん、コード例http://codepen.io/yarnball/pen/GqbyWr? – Ycon