FlowRouter.go => How: getInitialState?


#1

Pretty new on both Meteor and React so would like to know how to do getInitialState correctly after using FlowRouter.go the correct way.

My current setup is something like this

// Initial State

getInitialState: function () {
  if (_.include(this.props.video.upvoters, this.props.userId)) {
    return {like: true}
  } else {
    return {like: false};
  }
},

// dissLike

handleDissLike: function (event) {
  this.setState({dissLike: !this.state.dissLike});
  Videos.update({_id: this.props.video._id}, {
    $pull: {upvoters:this.props.userId
    },
    $inc: { votes: -1} });
    setTimeout(() => {
      FlowRouter.go('/video/' + this.props.next);
    }, 2500)    ;

  },

So when accessing url directly or by href is will trigger getInitialState but when using FlowRouter.go it don’t seem to work.

If anyone would be kind to explain the correct way to do this is would be to huge help to get me on the right track.

using FR SSR

This is my route

 FlowRouter.route('/video/:_id', {
    name: 'video',
    action: function(params, require) {
      ReactLayout.render(VideoLayout, {
       content: <VideoPage _id={params._id} />
    });
  }
});

RangeError stack size @ Render: if include with props ( React )
#2

You’re passing a prop _id into VideoPage, but then you try to reference this.props.video._id. Shouldn’t it be this.props._id?


#3

Component is a child component to VideoPage

 VideoPage = React.createClass({
      mixins: [ReactMeteorData],
      getMeteorData() {
        var selector = {};
        var handle = Meteor.subscribe('videos', selector);
        var data = {};
        data.userId = Meteor.userId();
        data.video = Videos.findOne({_id: this.props._id});
        data.next = Videos.findOne({_id: {$gt: this.props._id}});
        data.previous = Videos.findOne({_id: {$lt: this.props._id}});
        return data;
    
    
    
      },
    
      
      getContent() {
        return <div>
          <Youtube video={this.data.video} />
          <LikeBox
            next={this.data.next._id}
            previous={this.data.previous._id}
            userId={this.data.userId}
            video={this.data.video} />
        </div>
        ;
      },
    
    
      render() {
        return <div>
          
          {(this.data.video)? this.getContent() :
            <Loading/>
          }
          
          
          
        </div>;
      }
    }) ;

The code in my first post is from the LikeBox component and my issue is that when using FlowRouter.go() to load next video i can’t get getInitialState to work. Accessing directly by url i will work.