Skip to content

Instantly share code, notes, and snippets.

@nicolaslopezj
Last active August 30, 2016 14:00
Show Gist options
  • Save nicolaslopezj/c5a449a648a344605238737dc0a3bdf5 to your computer and use it in GitHub Desktop.
Save nicolaslopezj/c5a449a648a344605238737dc0a3bdf5 to your computer and use it in GitHub Desktop.
// with-post.js
import {withData} from 'meteor/orionsoft:react-meteor-data'
import {Meteor} from 'meteor/meteor'
import Posts from './posts'
export default withData(({postId}) => {
Meteor.subscribe('post', postId)
const post = Posts.findOne(postId)
return {post}
})
// with-author.js
import {withData} from 'meteor/orionsoft:react-meteor-data'
import {Meteor} from 'meteor/meteor'
import Authors from './authors'
export default withData(({post}) => {
if (!post) return {}
Meteor.subscribe('author', post.authorId)
const author = Authors.findOne(itemId)
return {author}
})
// my-component.js
import React from 'react'
import withPost from './with-post.js'
import withAuthor from './with-author.js'
@withPost
@withAuthor
export default class Component extends React.Component {
render () {
if (!this.props.post || !this.props.author) return <span>Loading...</span>
return (
<div>
{this.props.post.title} by {this.props.author.name}
</div>
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment