Skip to content

Instantly share code, notes, and snippets.

@theodorDiaconu
Created August 31, 2016 14:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save theodorDiaconu/80c5aec8f70886dbbd386039a56ab161 to your computer and use it in GitHub Desktop.
Save theodorDiaconu/80c5aec8f70886dbbd386039a56ab161 to your computer and use it in GitHub Desktop.
React Meteor Method Container
import React from 'react';
/**
* Method container for React. Very helpful to avoid boilerplate code.
*
* export default methodContainer((props) => { method, param }, Component)
* Will send {error, data, ready} as props to the specified Component
*
* On behalf of www.drivindu.com
*
* @param callDataFn
* @param component
* @returns {*}
*/
export default (callDataFn, component) => {
return class extends React.Component {
constructor() {
super();
this.state = {
ready: false
}
}
componentWillMount() {
const callData = callDataFn(this.props);
Meteor.call(callData.method, callData.param, (error, data) => {
this.setState({
error,
data,
ready: true
})
})
}
render() {
return React.createElement(component, this.state)
}
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment