# react-ssr-request

> Server-Side React Rendering. Request data

Latest version **1.0.14** (published 2018-01-09) · MIT license · 0 weekly downloads

## Install

```sh
npm install react-ssr-request
pnpm add react-ssr-request
yarn add react-ssr-request
bun add react-ssr-request
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.14 |
| Published | 2018-01-09 |
| First published | 2018-01-07 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | tangzuo |
| Maintainers | tzuser |
| Keywords | react, ssr, request |

## Links

- npm: https://www.npmjs.com/package/react-ssr-request
- Repository: https://github.com/tzuser/react-ssr-request
- Homepage: https://github.com/tzuser/react-ssr-request#readme
- Issues: https://github.com/tzuser/react-ssr-request/issues
- npm.io page: https://npm.io/package/react-ssr-request

## Dependencies (2)

- [react](https://npm.io/package/react.md) ^16.2.0
- [react-router](https://npm.io/package/react-router.md) ^4.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

- 1.0.14 (latest) — 2018-01-09
- 1.0.13 — 2018-01-08
- 1.0.12 — 2018-01-08
- 1.0.11 — 2018-01-08
- 1.0.10 — 2018-01-08
- 1.0.9 — 2018-01-07
- 1.0.8 — 2018-01-07
- 1.0.7 — 2018-01-07
- 1.0.5 — 2018-01-07
- 1.0.4 — 2018-01-07
- 1.0.3 — 2018-01-07
- 1.0.2 — 2018-01-07
- 1.0.1 — 2018-01-07
- 1.0.0 — 2018-01-07

## README

# React-Inital-Request 针对Router4服务端渲染首次加载数据


## 安装
``` 
npm install --save react-ssr-request

```

## 使用说明


### 需要首次加载的组件
```
import React,{Component} from 'react';
import {initialRequest} from 'react-ssr-request';
import * as Acts from '../actions/Test';

class Home extends Component{
  render(){
    ...
  }
 }
 
const initialDispatchs=(state)=>[
  Acts.get(1),
]
export default initialRequest(initialDispatchs)(Home)
```
### 注意 initialRequest必须包裹在最外层
例如
`initialRequest(initialDispatchs)(connect(...)(Home))`



### 在webpack发布环境的配置文件里引用插件

`const ReactSSRRequest =require('react-ssr-request/webpack');`

添加插件
```
plugins:[
  new ReactSSRRequest()
]
```
添加组件后执行build后会生成router-config.json文件





### 服务端
```
import initalActions from 'react-ssr-request/server';
import initialRequestConfig from '../build/router-config.json';


const render=async (ctx,next)=>{
  //获取store
  const { store, history } = getCreateStore(ctx.req.url);
  //保证所有请求完成
  await initalActions(store,ctx.req.url,initialRequestConfig)
  
  let routeMarkup =renderToString(...)
}
```

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