首页 > 解决方案 > 尝试使用 react-meteor-hooks 订阅集合,但加载总是正确的

问题描述

试图实现'react-meteor-hooks,但'loading'变量总是正确的:

import React from 'react';
import { useSubscription, useMongoFetch } from 'react-meteor-hooks';
import { Comments } from '../../../../collections/comments';

export const GiveComments = (props) => {

     const loading = useSubscription('getComments');

    if (loading) {
         console.log('loading... ');
    } else {
        const allComments = useMongoFetch(Comments.find({}));
        console.log('loaded: ', allComments);
      }
    return (null);
};

出版:

  Meteor.publish('getComments', function() {
    return Comments.find({});
  });

这些钩子看起来很神奇,但不能让它工作。为什么“加载”不会停止?

标签: meteorreact-hookspublish-subscribemeteor-react

解决方案


推荐阅读