私はページ作成を作成するためにReduxを使用しています。私の問題は、constructor
です。私はURLを解析し、ページネーションについて何かがあるかどうかをチェックする方法を実行しました。それから、私の店にデータを入れるアクションを実行します。それはすべてスムーズに実行されます。React - コンストラクタ()とcomponentDidMount
次に、データをフェッチする別のアクションを実行すると、componentDidMount
メソッドがあります。そして、私は以前にプッシュした小道具を使用します。残念ながら、店舗は初期状態です。
マイ(簡体字)コード:
class NewsList extends React.Component {
constructor(props) {
super(props);
this.profile = document.getElementById('articles').getAttribute('data-profile');
this.parseHash();
}
parseHash() {
/* Method for parsing navigation hash
---------------------------------------- */
const hash = window.location.hash.replace('#', '').split('&');
const data = {
page: 1,
offset: 0
};
// hash parsing
this.props.setPagination(data);
}
componentDidMount() {
this.loadNews();
// If I use
// setTimeout(() => { this.loadNews(); })
// it works, but I feel this is hack-ish
}
loadNews() {
this.props.update({
current: {page: this.props.NewsListReducer.current.page, offset: this.props.NewsListReducer.current.offset},
next: {page: this.props.NewsListReducer.next.page, offset: this.props.NewsListReducer.next.offset}
});
}
}
I console.log(this.props.NewsListReducer)
、私は両方current
とnext
オブジェクトに対してundefined
を取得していますが、私はReduxのデベロッパーツールを使用する場合、データがあります。私に何ができる?
this.parseHash()をcomponentWillMount()に移動してみてください。 – jzm
これは@jzmと同じです。 'constructor'は' componentWillMount() 'の代わりです。 –
純粋な反応のため。しかし、reduxのために、ここでの最後の答えを参照してください:http://stackoverflow.com/a/37703446/769083 – jzm