Set up pre-loader on subscription in Meteor Container?

Hello, help needed!

I’m trying to find out the best way of using findOne within createContainer (react-meteor-data), so if I findOne from within createContainer and this.props.MyReturnedObject is undefined for a moment until collection becomes ready then it breaks the app… I know I could use subscription handle and hook everything on it to load until it is pulled down but its a little frustrating to do that on every component I need data… Is there a better way, like in Angular I wouldn’t have to hook everything on subscription ready… ?

Also if I console log this.props.MyReturnedObject in render() function it would console log the object more than once, is this expected behaviour?

Another thing Component.propTypes = { key: PropTypes.type.isRequired } would throw an error until subscription is ready… ?

Thank you!!

One of the inherent properties of a reactive system is that not all of the data will be present immediately. Currently you need to be aware of that and handle it manually, for example you could return a default value for that data or write an intermediate component that displays a loading state. The different use cases are too diverse so it’s hard to come up with a generic system that will handle loading without any intervention from the app developer.

Thank you sashko, thats all I wanted to know, just making sure I’m on the right path. So basically I could make a global component and within render() functions where I need data do something like

(subscriptionHandle.ready()) ? <Component object={this.props.object} /> : <Loader />

function Component () => {
 render(){...}
}

Cheers!

1 Like