Guest User

Untitled

a guest
Nov 24th, 2017
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1. componentWillReceiveProps(nextProps) {
  2. console.log(`ChannelSelectorNewsContainer`, `componentWillReceiveProps`, nextProps)
  3. if (!this.props.feedGroup.news && nextProps.feedGroup.news) {
  4. console.log(`ChannelSelectorNewsContainer`, `componentWillReceiveProps`, 'will refresh')
  5. return this.setState({
  6. shouldRefresh: true
  7. });
  8. }
  9.  
  10. let newNewsArrived = false;
  11. if (!!nextProps.feedGroup.news && nextProps.feedGroup.news.length > 0) {
  12. if (!!this.props.feedGroup.news) {
  13. newNewsArrived = true;
  14. } else {
  15. newNewsArrived = nextProps.feedGroup.news.length !== this.props.feedGroup.news.length && newsProps.feedGroup.news.length > 0;
  16. }
  17. }
  18.  
  19. const shouldRefresh = this.props.currentUser.id !== nextProps.currentUser.id ||
  20. this.props.feedGroup.id !== nextProps.feedGroup.id ||
  21. newNewsArrived;
  22.  
  23. console.log(`ChannelSelectorNewsContainer`, `componentWillReceiveProps this.props.currentUser.id !== nextProps.currentUser.id`, this.props.currentUser.id !== nextProps.currentUser.id)
  24. console.log(`ChannelSelectorNewsContainer`, `componentWillReceiveProps this.props.feedGroup.id !== nextProps.feedGroup.id`, this.props.feedGroup.id !== nextProps.feedGroup.id)
  25. console.log(`ChannelSelectorNewsContainer`, `componentWillReceiveProps newNewsArrived`, newNewsArrived)
  26. if (shouldRefresh) {
  27. this.setState({
  28. shouldRefresh
  29. });
  30. }
  31. }
  32.  
  33. shouldComponentUpdate() {
  34. // we actually cannot compare `this.props` and `nextProps` there - they are already assigned there, after `componentWillReceiveProps` !!
  35. return this.state.shouldRefresh || !this.state.initialRefreshDone;
  36. }
Add Comment
Please, Sign In to add comment