{"id":17060144,"url":"https://github.com/latentflip/async-data-loader","last_synced_at":"2025-11-01T04:04:21.980Z","repository":{"id":66886100,"uuid":"47196941","full_name":"latentflip/async-data-loader","owner":"latentflip","description":null,"archived":false,"fork":false,"pushed_at":"2015-12-01T15:36:38.000Z","size":5,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-28T14:47:06.760Z","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/latentflip.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}},"created_at":"2015-12-01T15:05:33.000Z","updated_at":"2017-10-16T20:30:07.000Z","dependencies_parsed_at":"2023-03-13T21:25:35.659Z","dependency_job_id":null,"html_url":"https://github.com/latentflip/async-data-loader","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/latentflip%2Fasync-data-loader","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/latentflip%2Fasync-data-loader/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/latentflip%2Fasync-data-loader/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/latentflip%2Fasync-data-loader/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/latentflip","download_url":"https://codeload.github.com/latentflip/async-data-loader/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245072268,"owners_count":20556353,"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-10-14T10:36:20.674Z","updated_at":"2025-11-01T04:04:21.930Z","avatar_url":"https://github.com/latentflip.png","language":"JavaScript","readme":"# Simple data-loading for React\n\nThis is not meant to replace something like a flux architecture as an app grows, but more to provide a starting point for simple data loading.\n\nA higher-order-component, wraps \"Page\" components and describe their data requirements as a promise, or object of `keys =\u003e promises`.\n\nCurrently assumes you are using react router.\n\n## Example\n\n### In your app.js or wherever\n\n```javascript\nimport React from 'react';\nimport ReactDOM from 'react-dom';\n\nimport { ApiProvider } from 'async-data-loader';\nimport HatsIndexPage from './pages/hats-index';\n\nlet api = new SomeApiWrapperForCurrentUser();\n\nReactDOM.render(\n  \u003cApiProvider api={api}\u003e\n    \u003cRouter history={history}\n      \u003cRoute path='/' component={HatsIndexPage} /\u003e\n      //...routes\n    \u003c/Router\u003e\n  \u003c/ApiProvider\u003e\n, document.getElementById('app'));\n```\n\n### In a \"page\" component\n\n```javascript\nimport React from 'react';\nimport { connectApi } from 'async-data-loader';\n\nconst HatsIndex = React.createClass({\n  render() {\n    let { hats, fetching, fetchError } = this.props;\n\n    // while data is still loading, fetching will be true\n    if (fetching) {\n      return (\u003cp\u003eLoading\u003c/p\u003e);\n    }\n\n    // if any promises error, this will be set\n    if (fetchError) {\n      return (\u003cp\u003eLoading error: {fetchError}\u003c/p\u003e);\n    }\n\n    // once all loaded, your props will be available\n    return (\n      \u003cdiv\u003e\n        \u003ch1\u003eHats:\u003c/h1\u003e\n        \u003cul\u003e\n          { hats.map(hat =\u003e (\n            \u003cli\u003e{hat.id}: {hat.name} - {hat.color}\u003c/li\u003e\n          ))}\n        \u003c/ul\u003e\n      \u003c/div\u003e\n    );\n  }\n});\n\n//connectApi takes two arguments, mapProps, mapActions\n\n// mapProps should be a function which receives the api, and the page's original props, and returns a promise of an object, or an object of promises, for the data to load:\n\n// api - is as injected by ApiProvider\n// props - is as passed from the router/renderer\n// each key of the object returned here will be set as a prop on the page, once promises have resolved\nlet mapProps = function (api, props) {\n  return {\n    hats: api.fetch('/hats') // promises as object values will be resolved before being passed as props\n  };\n}\n\n// lets come back to this\nlet mapActions = null;\n\nexport default connectApi(mapProps, mapActions)(HatsIndex);\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flatentflip%2Fasync-data-loader","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flatentflip%2Fasync-data-loader","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flatentflip%2Fasync-data-loader/lists"}