Last active
September 2, 2021 16:54
-
-
Save CaptainN/17c0e3da64e650e4e72a4a85a33794d6 to your computer and use it in GitHub Desktop.
Meteor Basic useTracker
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useTracker } from 'meteor/react-meteor-data' | |
// Hook, basic use, everything in one component | |
const MyPage = (pageId) => { | |
const { user, isLoggedIn, page } = useTracker(() => { | |
// The publication must also be secure | |
const subscription = Meteor.subscribe('page', pageId) | |
const page = Pages.findOne({ _id: pageId }) | |
return { | |
page, | |
isLoading: !subscription.ready() | |
} | |
}, [pageId]) | |
return <div> | |
<h1>{page.title}</h1> | |
<p>{page.content}</p> | |
</div>) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment