{"id":13671836,"url":"https://github.com/nicolaslopezj/react-meteor-data","last_synced_at":"2025-04-22T22:16:14.666Z","repository":{"id":66339958,"uuid":"66936038","full_name":"nicolaslopezj/react-meteor-data","owner":"nicolaslopezj","description":"Fetch Meteor data in React using decorators","archived":false,"fork":false,"pushed_at":"2017-04-05T15:14:32.000Z","size":10,"stargazers_count":38,"open_issues_count":2,"forks_count":3,"subscribers_count":12,"default_branch":"master","last_synced_at":"2025-03-29T19:21:50.557Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nicolaslopezj.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2016-08-30T11:50:33.000Z","updated_at":"2021-07-05T20:34:46.000Z","dependencies_parsed_at":"2023-02-23T04:00:47.480Z","dependency_job_id":null,"html_url":"https://github.com/nicolaslopezj/react-meteor-data","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nicolaslopezj%2Freact-meteor-data","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nicolaslopezj%2Freact-meteor-data/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nicolaslopezj%2Freact-meteor-data/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nicolaslopezj%2Freact-meteor-data/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nicolaslopezj","download_url":"https://codeload.github.com/nicolaslopezj/react-meteor-data/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249297795,"owners_count":21246477,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-02T09:01:19.998Z","updated_at":"2025-04-17T01:31:59.496Z","avatar_url":"https://github.com/nicolaslopezj.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# React Meteor Data\n\nFetch Meteor data in React using decorators\n\nMedium Post\n\n- [Using decorators to fetch Meteor data in React](https://medium.com/orionsoft/using-decorators-to-fetch-meteor-data-in-react-419a6869400c)\n- [Using Meteor methods on React components to fetch data](https://medium.com/orionsoft/using-meteor-methods-on-react-components-to-fetch-data-8f98431a6252)\n\n### Installing\n\nInstall the package\n\n```\nmeteor add orionsoft:react-meteor-data\n```\n\nInstall the babel decorator\n\n```\nnpm install --save-dev babel-plugin-transform-decorators-legacy\n```\n\nCreate or update the ```.babelrc``` file in the root of your app\n\n```js\n{\n  \"plugins\": [\n    \"babel-plugin-transform-decorators-legacy\"\n  ]\n}\n```\n\n### Example with publication\n\n```js\nimport React from 'react'\nimport {Meteor} from 'meteor/meteor'\nimport {withData} from 'meteor/orionsoft:react-meteor-data'\nimport MyCollection from './my-collection'\n\n/**\n * Prop will be checked also in the container\n */\nconst propTypes = {\n  itemId: React.PropTypes.string.isRequired,\n  isLoading: React.PropTypes.bool,\n  item: React.PropTypes.string\n}\n\n@withData(({itemId}) =\u003e {\n  const handler = Meteor.subscribe('myPublication', itemId)\n  const isLoading = !handler.ready()\n  const item = MyCollection.findOne(itemId)\n  return {isLoading, item}\n})\nexport default class Component extends React.Component {\n\n  render () {\n    if (this.props.isLoading) return \u003cspan/\u003e\n    return (\n      \u003cdiv\u003e\n        {this.props.item.name}\n      \u003c/div\u003e\n    )\n  }\n\n}\n\nComponent.propTypes = propTypes\n```\n\n### Example with method\n\n```js\nimport React from 'react'\nimport {Meteor} from 'meteor/meteor'\nimport {withMethodData} from 'meteor/orionsoft:react-meteor-data'\n\n/**\n * Prop will be checked also in the container\n */\nconst propTypes = {\n  itemId: React.PropTypes.string.isRequired,\n  isLoading: React.PropTypes.bool,\n  item: React.PropTypes.string\n}\n\n@withMethodData(({itemId}, ready) =\u003e {\n  Meteor.call('getItem', itemId, ready)\n})\nexport default class Component extends React.Component {\n\n  render () {\n    if (this.props.isLoading) return \u003cspan/\u003e\n    return (\n      \u003cdiv\u003e\n        {this.props.item.name}\n      \u003c/div\u003e\n    )\n  }\n\n}\n\nComponent.propTypes = propTypes\n\n// On the server\nMeteor.methods({\n  'getItem': function (itemId) {\n    const item = Items.findOne(itemId)\n    return {item} // objects returned in the method will be passed as props\n  }\n})\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnicolaslopezj%2Freact-meteor-data","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnicolaslopezj%2Freact-meteor-data","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnicolaslopezj%2Freact-meteor-data/lists"}