{"id":17172268,"url":"https://github.com/lucasconstantino/react-data-loader","last_synced_at":"2025-07-30T09:05:05.118Z","repository":{"id":65372842,"uuid":"95627124","full_name":"lucasconstantino/react-data-loader","owner":"lucasconstantino","description":"Dead simple data loader helper for React","archived":false,"fork":false,"pushed_at":"2019-04-16T16:53:14.000Z","size":132,"stargazers_count":22,"open_issues_count":1,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-06-17T10:17:28.121Z","etag":null,"topics":["data","higher-order-component","loader","react"],"latest_commit_sha":null,"homepage":null,"language":null,"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/lucasconstantino.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-06-28T04:00:51.000Z","updated_at":"2021-06-10T20:40:17.000Z","dependencies_parsed_at":"2023-01-19T23:35:32.138Z","dependency_job_id":null,"html_url":"https://github.com/lucasconstantino/react-data-loader","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/lucasconstantino/react-data-loader","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lucasconstantino%2Freact-data-loader","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lucasconstantino%2Freact-data-loader/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lucasconstantino%2Freact-data-loader/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lucasconstantino%2Freact-data-loader/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lucasconstantino","download_url":"https://codeload.github.com/lucasconstantino/react-data-loader/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lucasconstantino%2Freact-data-loader/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267842978,"owners_count":24153133,"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","status":"online","status_checked_at":"2025-07-30T02:00:09.044Z","response_time":70,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["data","higher-order-component","loader","react"],"created_at":"2024-10-14T23:36:33.502Z","updated_at":"2025-07-30T09:05:05.085Z","avatar_url":"https://github.com/lucasconstantino.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# React Data Loader [![Build Status](https://travis-ci.org/lucasconstantino/react-data-loader.svg?branch=master)](https://travis-ci.org/lucasconstantino/react-data-loader)\n\n\u003e Dead simple data loader helper for React\n\n## Disclaimer\n\nUse it not for big projects! If you project needs lots of API communication you'll be probably better off using tools such as [GraphQL](http://graphql.org/) (I personally recommend [Apollo](https://www.apollodata.com/) for that task) or even [Redux](http://redux.js.org/) with [`redux-thunk`](https://github.com/gaearon/redux-thunk). Sometimes, though, these are too much.\n\n## Why this package?\n\nWhen loading external data in a React component - be it on user interaction or during mounting phase - we end up rewriting the same logic all over again: loading status, error responses, etc. This could be much simpler and a lot more standardized. Nowadays we use component composition and Higher-Order Components and they are cool. Let's use them.\n\n## Inspiration\n\nI've lately being coding most of my projects using the Apollo stack. As with any API client, the [Apollo/React](https://github.com/apollographql/react-apollo) integration package provides easy data [request status and meta information](http://dev.apollodata.com/react/queries.html#default-result-props), right in the component as a simple prop. I wanted that when coding simpler projects too, but without API setup hassle :)\n\n## Install\n\n`yarn add react-data-loader`\n\n\u003e Or, good ol' `npm install --save react-data-loader`\n\n## Usage\n\nThis lib provides a single Higher-Order Component called `withDataLoader` with the following signature:\n\n```js\nwithDataLoader(\n  propName: string,\n  loader: (props: Object) =\u003e Function\n): HigherOrderComponent\n```\n\nThis HoC will inject an object on the property defined by `propName`. The object will have these keys:\n\nkey  | type | default | description\n-----|------|---------|------------\ndata | `any` | `undefined` | The resulting data. Can be anything you need.\nloading | `Boolean` | `false` | Whether or not the loader is currently fetching data.\nerror | `any` | `null` | The failure result. Can be anything you need (most commonly an `Error` instance).\nrequests | `Number` | `0` | The amount of times data was fetched using this loader.\npromise | `Promise` | `null` | The currently running data fetching promise.\nload | `Function` | | The data fetch dispatcher function. Can be called with whatever arguments your `loader` accepts.\n\nThe `loader` argument of `withDataLoader` is where the fun happens. It follows a similar specification as that of the [`withHandlers` from Recompose](https://github.com/acdlite/recompose/blob/master/docs/API.md#withhandlers) lib: it must be a Higher-Order Function which will receive `props` and must return a function responsible for fetching data.\n\n### Simple as can\n\n```js\nimport { withDataLoader } from 'react-data-loader'\n\nconst MyDataLoaderComponent = ({ someProp }) =\u003e (\n  \u003cdiv\u003e\n    { JSON.stringify(someProp.data) }\n    \u003cbutton onClick={ someProp.load } disabled={ someProp.loading }\u003eLoad!\u003c/button\u003e\n  \u003c/div\u003e\n)\n\n// Using Fetch API.\nconst loader = props =\u003e e =\u003e fetch('/api/data.json').then(res =\u003e res.json())\n\nexport default withDataLoader('someProp', loader)(MyDataLoaderComponent)\n```\n\n## License\n\nCopyright (c) 2017 Lucas Constantino Silva\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of\nthis software and associated documentation files (the \"Software\"), to deal in\nthe Software without restriction, including without limitation the rights to\nuse, copy, modify, merge, publish, distribute, sublicense, and/or sell copies\nof the Software, and to permit persons to whom the Software is furnished to do\nso, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flucasconstantino%2Freact-data-loader","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flucasconstantino%2Freact-data-loader","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flucasconstantino%2Freact-data-loader/lists"}