Blocks
Meteor Subscribe with useTracker()
Sample code that uses useTracker in order to subscribe and read the pointers of a published colletion on Meteor.
Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
Sample code that uses useTracker in order to subscribe and read the pointers of a published colletion on Meteor.
Meteor.publish('users', function() {
return Users.find();
});
import React from 'react';
import { useTracker } from 'meteor/react-meteor-data';
export const UsersComponent = () => {
const { users, isLoading } = useTracker(() => {
const noDataAvailable = { users: [] };
const handler = Meteor.subscribe('users');
if (!handler.ready()) {
return { ...noDataAvailable, isLoading: true };
}
const users = Users.find().fetch();
return { users };
});
return (
<div>
{isLoading ? (
<p>Loading...</p>
) : (
<ul>
{users.map((user, index) => (
<li key={user._id}>{user.name}</li>
))}
</ul>
)}
</div>
);
};