{"id":13437849,"url":"https://github.com/andreypopp/react-async","last_synced_at":"2025-04-05T20:07:07.141Z","repository":{"id":13971685,"uuid":"16672290","full_name":"andreypopp/react-async","owner":"andreypopp","description":"[DEPRECATED] Asynchronously fetch data for React components","archived":false,"fork":false,"pushed_at":"2016-08-22T14:22:17.000Z","size":746,"stargazers_count":444,"open_issues_count":15,"forks_count":24,"subscribers_count":18,"default_branch":"master","last_synced_at":"2025-03-29T19:05:20.053Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/andreypopp.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-02-09T18:25:25.000Z","updated_at":"2025-03-04T10:53:08.000Z","dependencies_parsed_at":"2022-08-07T07:16:03.731Z","dependency_job_id":null,"html_url":"https://github.com/andreypopp/react-async","commit_stats":null,"previous_names":[],"tags_count":27,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andreypopp%2Freact-async","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andreypopp%2Freact-async/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andreypopp%2Freact-async/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andreypopp%2Freact-async/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/andreypopp","download_url":"https://codeload.github.com/andreypopp/react-async/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247393569,"owners_count":20931812,"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-07-31T03:01:00.677Z","updated_at":"2025-04-05T20:07:07.111Z","avatar_url":"https://github.com/andreypopp.png","language":"JavaScript","readme":"# React Async\n\n**VERSION DESCRIBED IN THIS DOCUMENT IS NOT RELEASED YET**\n\nReact Async provides a way for React components to subscribe for observable\nvalues.\n\n## Installation\n\nReact Async is packaged on npm:\n```sh\n$ npm install react-async\n```\n\n## Basic usage\n\nReact Async provides a component decorator `@Async` which given a set of\nobservable specifications wraps a regular React component and returns a new one\nwhich subscribes to observables and re-renders the component when new data\narrives.\n\nThe basic example looks like:\n\n```js\nimport React from 'react';\nimport Async from 'react-async';\nimport Rx from 'rx';\n\nfunction defineXHRObservable(url) {\n  return {\n    id: url,\n    start() {\n      return Rx.fromPromise(fetch(url))\n    }\n  }\n}\n\nfunction MyComponentObservables(props) {\n  return {\n    user: defineXHRObservable(`/api/user?user${props.userID}`)\n  }\n}\n\n@Async(MyComponentObservables)\nclass MyComponent extends React.Component {\n\n  render() {\n    let {user} = this.props\n    ...\n  }\n\n}\n```\n\nThe `@Async` decorator injects data from observables via props so in `render()`\nmethod of `\u003cMyComponent /\u003e` the `user` property will contain the data fetched\nvia XHR.\n\n## Rendering async components on server with fetched async state\n\nWhile React provides `renderToString(element)` function which can produce markup\nfor a component, this function is synchronous. That means that it can't be used\nwhen you want to get markup from server populated with data.\n\nReact Async provides another version of `renderToString(element)` which is\nasynchronous and fetches all data defined in observable specifications before\nrendering a passed component tree.\n\nFirst, you'd need to install `fibers` package from npm to use that function:\n```sh\n$ npm install fibers\n```\n\nThen use it like:\n```js\nimport {renderToString} from 'react-async';\n\nrenderToString(\n  \u003cComponent /\u003e,\n  function(err, markup) {\n    // send markup to browser\n  })\n```\n\nThis way allows you to have asynchronous components arbitrary deep in the\nhierarchy.\n","funding_links":[],"categories":["Awesome React","Uncategorized","Code Design","JavaScript"],"sub_categories":["Tools","Uncategorized","Props from server"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandreypopp%2Freact-async","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fandreypopp%2Freact-async","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandreypopp%2Freact-async/lists"}