Using react with meteor results in find not a function
I'm attempting to learn the react way of working with meteor and running into a pretty crucial, yet pretty basic problem. I'm trying to subscribe to some data, and then render that as a react component, and use react-template-helper
to display that component.
As soon as I try to render that component I get the following errors in the console.
Exception from Tracker afterFlush function: undefined
findOne is not a function
Or
find is not a function
My app template:
<template name="appLayout">
<nav class="fixed">
<ul class="centered">
<li><a target="_blank" rel="nofollow noreferrer" target="_blank" rel="nofollow noreferrer" href=""></a></li>
<li><a target="_blank" rel="nofollow noreferrer" target="_blank" rel="nofollow noreferrer" href=""></a></li>
<li><a target="_blank" rel="nofollow noreferrer" target="_blank" rel="nofollow noreferrer" href=""></a></li>
</ul>
<ul class="social">
<li><a target="_blank" rel="nofollow noreferrer" target="_blank" rel="nofollow noreferrer" href=""><i class="icon"></i></a></li>
<li><a target="_blank" rel="nofollow noreferrer" target="_blank" rel="nofollow noreferrer" href=""><i class="icon"></i></a></li>
</ul>
</nav>
{{> Template.dynamic template=yield}}
</template>
<template name="home">
<section class="home-hero">
{{> React component=homeContent}}
</section>
</template>
My react/meteor view logic:
Template.home.onCreated( function() {
let template = this;
template.autorun( function() {
Meteor.subscribe('homecontent');
})
});
homeContent = React.createClass({
mixins: [ReactMeteorData],
getMeteorData() {
return {
homeData: homeContent.find({}).fetch()
}
},
render(){
return (
<div className="units-container">
<div className="units-row centered-content stacked">
<h1>site name</h1>
<p>{this.data.homeData.homeCopy}</p>
</div>
</div>
)
}
})
Template.home.helpers({
homeContent() {
return homeContent
}
})
My router:
FlowRouter.route('/', {
action() {
BlazeLayout.render('appLayout', {
yield: 'home'
})
},
name: 'home'
})
My server publication:
Meteor.publish('homecontent', function(){
return homeContent.find();
})
I'm using the following packages to try and achieve react components through blaze: ecmascript, react, kadira:flow-router, kadira:blaze-layout, react-template-helper.
Of note, if I simply remove mixins
and getMeteorData
from my jsx file, everything renders fine and mini-mongo acts normally from the console.
Answer
Very simple mistake. at the line homeData: homeContent.find({}).fetch()
the call homeContent
refers to the react class I just made, not the collection I'm looking for.
The fix for this specific error is homeContent = React.createClass({
becomes homeComponent = React.createClass({
Related Questions
- → How to update data attribute on Ajax complete
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → Octobercms Component Unique id (Twig & Javascript)
- → Passing a JS var from AJAX response to Twig
- → Laravel {!! Form::open() !!} doesn't work within AngularJS
- → DropzoneJS & Laravel - Output form validation errors
- → Import statement and Babel
- → Uncaught TypeError: Cannot read property '__SECRET_DOM_DO_NOT_USE_OR_YOU_WILL_BE_FIRED' of undefined
- → React-router: Passing props to children
- → ListView.DataSource looping data for React Native
- → Can't test submit handler in React component
- → React + Flux - How to avoid global variable
- → Webpack, React & Babel, not rendering DOM