Skip to content

Instantly share code, notes, and snippets.

@CaptainN
Last active September 2, 2021 16:54
Show Gist options
  • Save CaptainN/17c0e3da64e650e4e72a4a85a33794d6 to your computer and use it in GitHub Desktop.
Save CaptainN/17c0e3da64e650e4e72a4a85a33794d6 to your computer and use it in GitHub Desktop.
Meteor Basic useTracker
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