# react-redux-universal-resolver

> Yet another redux based HOC to support universal async rendering.

Latest version **0.3.0** (published 2016-07-20) · MIT license · 0 weekly downloads

## Install

```sh
npm install react-redux-universal-resolver
pnpm add react-redux-universal-resolver
yarn add react-redux-universal-resolver
bun add react-redux-universal-resolver
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.3.0 |
| Published | 2016-07-20 |
| First published | 2016-06-22 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Yury Tarabanko |
| Maintainers | tarabyte |
| Keywords | react, redux, HOC, universal, async |

## Links

- npm: https://www.npmjs.com/package/react-redux-universal-resolver
- Repository: https://github.com/Tarabyte/react-redux-universal-resolver
- Homepage: https://github.com/Tarabyte/react-redux-universal-resolver#readme
- Issues: https://github.com/Tarabyte/react-redux-universal-resolver/issues
- npm.io page: https://npm.io/package/react-redux-universal-resolver

## Dependencies (3)

- [invariant](https://npm.io/package/invariant.md) ^2.2.1
- [shallowequal](https://npm.io/package/shallowequal.md) ^0.2.2
- [hoist-non-react-statics](https://npm.io/package/hoist-non-react-statics.md) ^1.2.0

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 0.3.0 (latest) — 2016-07-20
- 0.2.1 — 2016-07-19
- 0.2.0 — 2016-07-18
- 0.1.1 — 2016-06-22
- 0.1.0 — 2016-06-22

## README

#  react-redux-universal-resolver ![Experimental](https://img.shields.io/badge/status-experimental-red.svg)
Yet another ~~isomorphic~~ universal [redux](https://www.npmjs.com/package/react-redux) based async resolver for React.

> This project is __NOT__ production ready and might never would be.


## Motivation
I was playing with different approaches to handle data fetching in redux base application both on server and client. There are solutions [available](#similar-projects).
But I've decided to write my own to get a better understanding of universal applications.

General idea is well describe in redux [docs](http://redux.js.org/docs/recipes/ServerRendering.html):

### On Server
- You somehow "extract" each piece of data required for container components to be rendered based current route. Usually by filtering components that expose static `fetchData` method.
- Prefetch each piece "in parallel" on server. Save collected data to store.
- Serialize state and save string in global variable say `window.__INITIAL_STATE__`.
- Render components, wrap with html (doctype etc), and send response to client.

### On Client
- Create store using `window.__INITIAL_STATE__` as initial data.
- Later
  - Either Use `componentDidMount` hook to check if data was loaded. If not run data fetching process.
  - Or listen to history change events and orchestrate data fetching process the same way it was done on server.

It all sounds like a lot of boilerplate code to write. And in fact it is. That's why there are almost a hundred of "boilerplate" [projects](http://andrewhfarmer.com/starter-project/) available. Each of which utilize some data fetching package.

### Basic Requirements
- Provide HOC that allows
  - Specify data requirements for component.
  - Provide custom mapping to fetching params based on current state and own component props on client.
  - Provide custom mapping to fetching params based on current state and router props on server.
  - Render another component when data is fetching (in-place loader indicators).
  - Render another component when data fetch failed (error message).
- Reduce serverside data prefetching to a single function call.
- Eliminate
  - Requirement for manual `componentDidMount` implementation.
  - Manual clientside fetching orchestration.
- Use redux store as the only source of state.
- Tests :lol:.


## Installation

Assuming you have node and npm installed (not publish yet)

``` npm install --save react-redux-universal-resolver ```

## Docs
- [API](docs/API.md)
 - [`resolver(mapParamsToPromises, [mapStateToParams], [mapRouteToParams], [options])`](docs/API.md#resolver)
 - [`resolveOnServer(components, state, routeProps, dispatch)`](docs/API.md#resolveOnServer)
- [Usage](docs/EXAMPLE.md)

## Similar Projects

- [ReduxAsyncConnect](https://github.com/Rezonans/redux-async-connect). Provides `@asyncConnect` decorator and `ReduxAsyncConnect` component to orchestrate data loading. Uses redux to manage state.
- [react-resolver](https://github.com/ericclemmons/react-resolver). Provides `@resolve` decorator. Not redux based.
- [redial](https://github.com/markdalgleish/redial). Provides `@provideHooks` decorator. Not redux based.

---
_Source: https://npm.io/package/react-redux-universal-resolver · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
