How to adjust the flow of meteorite data?

I use a reaction and a meteorite, I have problems getting data from the server at a time. The component receives data in the stream, and the component visualization function is called several times.

This is the code that I use to receive messages from the server on the client inside the responsive component using mixin.

getMeteorData() {
        return {
            posts: Posts.find({}, {sort: {createdAt: -1}}).fetch()
        }
    },

At the moment, it receives all messages from the server (there are only about 20 there)

How to get data from the server immediately so that it is not broadcast and repeatedly calls the rendering function?

+4
source share
1 answer

Add an additional check if the data is loading, for example:

  mixins: [ ReactMeteorData ],
  getMeteorData() {
    var subscription = Meteor.subscribe( 'posts' );

    return {
      isLoading: !subscription.ready(),
      posts: Posts.find({}, {sort: {createdAt: -1}}).fetch()
    };
  },
  render() {
    if ( this.data.isLoading ) {
      return <div>Loading...</div>;
    } else {
      return (
        // now we have data and render once
      );
    }
  }
+2
source

Source: https://habr.com/ru/post/1620261/


All Articles