{"id":13437855,"url":"https://github.com/brocoders/redux-async-connect","last_synced_at":"2025-04-04T22:07:07.214Z","repository":{"id":57350257,"uuid":"49886456","full_name":"brocoders/redux-async-connect","owner":"brocoders","description":"It allows you to request async data, store them in redux state and connect them to your react component.","archived":false,"fork":false,"pushed_at":"2019-09-23T19:54:20.000Z","size":45,"stargazers_count":644,"open_issues_count":59,"forks_count":101,"subscribers_count":14,"default_branch":"master","last_synced_at":"2025-03-28T21:06:42.951Z","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/brocoders.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":"2016-01-18T15:42:25.000Z","updated_at":"2025-01-06T19:49:36.000Z","dependencies_parsed_at":"2022-08-28T19:00:35.790Z","dependency_job_id":null,"html_url":"https://github.com/brocoders/redux-async-connect","commit_stats":null,"previous_names":["rezonans/redux-async-connect"],"tags_count":17,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brocoders%2Fredux-async-connect","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brocoders%2Fredux-async-connect/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brocoders%2Fredux-async-connect/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brocoders%2Fredux-async-connect/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/brocoders","download_url":"https://codeload.github.com/brocoders/redux-async-connect/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247256112,"owners_count":20909240,"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.721Z","updated_at":"2025-04-04T22:07:07.183Z","avatar_url":"https://github.com/brocoders.png","language":"JavaScript","funding_links":[],"categories":["Uncategorized"],"sub_categories":["Uncategorized"],"readme":"ReduxAsyncConnect for React Router\n============\n[![npm version](https://img.shields.io/npm/v/redux-async-connect.svg?style=flat-square)](https://www.npmjs.com/package/redux-async-connect)\n\nHow do you usually request data and store it to redux state?\nYou create actions that do async jobs to load data, create reducer to save this data to redux state, \nthen connect data to your component or container.\n\nUsually it's very similar routine tasks.\n\nAlso, usually we want data to be preloaded. Especially if you're building universal app, \nor you just want pages to be solid, don't jump when data was loaded.\n\nThis package consist of 2 parts: one part allows you to delay containers rendering until some async actions are happening.\nAnother stores your data to redux state and connect your loaded data to your container.\n\n## Installation \u0026 Usage\n\nUsing [npm](https://www.npmjs.com/):\n\n    $ npm install redux-async-connect\n\n```js\nimport { Router, browserHistory } from 'react-router';\nimport { ReduxAsyncConnect, asyncConnect, reducer as reduxAsyncConnect } from 'redux-async-connect'\nimport React from 'react'\nimport { render } from 'react-dom'\nimport { createStore, combineReducers } from 'redux';\n\n// 1. Connect your data, similar to react-redux @connect\n@asyncConnect({\n  lunch: (params, helpers) =\u003e Promise.resolve({id: 1, name: 'Borsch'})\n})\nclass App extends React.Component {\n  render() {\n    // 2. access data as props\n    const lunch = this.props.lunch\n    return (\n      \u003cdiv\u003e{lunch.name}\u003c/div\u003e\n    )\n  }\n}\n\n// 3. Connect redux async reducer\nconst store = createStore(combineReducers({reduxAsyncConnect}), window.__data);\n\n// 4. Render `Router` with ReduxAsyncConnect middleware\nrender((\n  \u003cProvider store={store} key=\"provider\"\u003e\n    \u003cRouter render={(props) =\u003e \u003cReduxAsyncConnect {...props}/\u003e} history={browserHistory}\u003e\n      \u003cRoute path=\"/\" component={App}/\u003e\n    \u003c/Router\u003e\n  \u003c/Provider\u003e\n), el)\n```\n\n### Server\n\n```js\nimport { renderToString } from 'react-dom/server'\nimport { match, RoutingContext } from 'react-router'\nimport { ReduxAsyncConnect, loadOnServer, reducer as reduxAsyncConnect } from 'redux-async-connect'\nimport createHistory from 'history/lib/createMemoryHistory';\nimport {Provider} from 'react-redux';\nimport { createStore, combineReducers } from 'redux';\n\napp.get('*', (req, res) =\u003e {\n  const history = createHistory();\n  const store = createStore(combineReducers({reduxAsyncConnect}));\n\n  match({ routes, location: req.url }, (err, redirect, renderProps) =\u003e {\n\n    // 1. load data\n    loadOnServer(renderProps, store).then(() =\u003e {\n\n      // 2. use `ReduxAsyncConnect` instead of `RoutingContext` and pass it `renderProps`\n      const appHTML = renderToString(\n        \u003cProvider store={store} key=\"provider\"\u003e\n          \u003cReduxAsyncConnect {...renderProps} /\u003e\n        \u003c/Provider\u003e\n      )\n\n      // 3. render the Redux initial data into the server markup\n      const html = createPage(appHTML, store)\n      res.send(html)\n    })\n  })\n})\n\nfunction createPage(html, store) {\n  return `\n    \u003c!doctype html\u003e\n    \u003chtml\u003e\n      \u003cbody\u003e\n        \u003cdiv id=\"app\"\u003e${html}\u003c/div\u003e\n\n        \u003c!-- its a Redux initial data --\u003e\n        \u003cscript dangerouslySetInnerHTML={{__html: `window.__data=${serialize(store.getState())};`}} charSet=\"UTF-8\"/\u003e\n      \u003c/body\u003e\n    \u003c/html\u003e\n  `\n}\n```\n\n## [API](/docs/API.MD)\n\n## Comparing with other libraries\n\nThere are some solutions of problem described above:\n\n- [**AsyncProps**](https://github.com/rackt/async-props)\n  It solves the same problem, but it doesn't work with redux state. Also it's significantly more complex inside, \n  because it contains lots of logic to connect data to props.\n  It uses callbacks against promises... \n- [**react-fetcher**](https://github.com/markdalgleish/react-fetcher)\n  It's very simple library too. But it provides you only interface for decorating your components and methods \n  to fetch data for them. It doesn't integrated with React Router or Redux. So, you need to write you custom logic\n  to delay routing transition for example.\n- [**react-resolver**](https://github.com/ericclemmons/react-resolver)\n  Works similar, but isn't integrated with redux. \n\n**Redux Async Connect** uses awesome [Redux](https://github.com/rackt/redux) to keep all fetched data in state.\nThis integration gives you agility: \n\n- you can react on fetching actions like data loading or load success in your own reducers\n- you can create own middleware to handle Redux Async Connect actions\n- you can connect to loaded data anywhere else, just using simple redux @connect\n- finally, you can debug and see your data using Redux Dev Tools\n\nAlso it's integrated with [React Router](https://github.com/rackt/react-router) to prevent routing transition \nuntil data is loaded.\n\n## Contributors\n- [Rodion Salnik](https://github.com/sars)\n- [Rezonans team](https://github.com/Rezonans)\n\n## Collaboration\nYou're welcome to PR, and we appreciate any questions or issues, please [open an issue](https://github.com/Rezonans/redux-async-connect/issues)!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrocoders%2Fredux-async-connect","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbrocoders%2Fredux-async-connect","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrocoders%2Fredux-async-connect/lists"}