Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- componentWillReceiveProps(nextProps) {
- console.log(`ChannelSelectorNewsContainer`, `componentWillReceiveProps`, nextProps)
- if (!this.props.feedGroup.news && nextProps.feedGroup.news) {
- console.log(`ChannelSelectorNewsContainer`, `componentWillReceiveProps`, 'will refresh')
- return this.setState({
- shouldRefresh: true
- });
- }
- let newNewsArrived = false;
- if (!!nextProps.feedGroup.news && nextProps.feedGroup.news.length > 0) {
- if (!!this.props.feedGroup.news) {
- newNewsArrived = true;
- } else {
- newNewsArrived = nextProps.feedGroup.news.length !== this.props.feedGroup.news.length && newsProps.feedGroup.news.length > 0;
- }
- }
- const shouldRefresh = this.props.currentUser.id !== nextProps.currentUser.id ||
- this.props.feedGroup.id !== nextProps.feedGroup.id ||
- newNewsArrived;
- console.log(`ChannelSelectorNewsContainer`, `componentWillReceiveProps this.props.currentUser.id !== nextProps.currentUser.id`, this.props.currentUser.id !== nextProps.currentUser.id)
- console.log(`ChannelSelectorNewsContainer`, `componentWillReceiveProps this.props.feedGroup.id !== nextProps.feedGroup.id`, this.props.feedGroup.id !== nextProps.feedGroup.id)
- console.log(`ChannelSelectorNewsContainer`, `componentWillReceiveProps newNewsArrived`, newNewsArrived)
- if (shouldRefresh) {
- this.setState({
- shouldRefresh
- });
- }
- }
- shouldComponentUpdate() {
- // we actually cannot compare `this.props` and `nextProps` there - they are already assigned there, after `componentWillReceiveProps` !!
- return this.state.shouldRefresh || !this.state.initialRefreshDone;
- }
Add Comment
Please, Sign In to add comment