天天看点

react、rematch、ssr脚手架启动套件

react-ssr-startkit

是一个基于React、Rematch(Redux)、Scss的服务端渲染脚手架,目的是为了快速启动一个项目,为业务开发多争取更多的时间而不是浪费太多的时间在基础设施上。

支持以下特性:

  1. 热更新
  2. 服务端渲染
  3. 单元测试
  4. Lint
  5. logger
rematch是redux的封装,帮你减掉了action和reducer的样板代码,同时处理异步也方便了许多。学习成本也非常低!在整合rematch做服务端渲染的时候有一点点不一样的地方就在于action的声明方式变了。

以前组件给服务端暴露action的的方式

// client
import { someAction } from './actions'
class Home extends React.Component {

}

Home.serverFetch = someAction

// server
dispatch(comp.serverFetch)
           

现在

// client
class Home extends React.Component {
// some logic
}

Home.serverFetch = {type: 'mode/someAction', payload: 1}

// server
 const {type, payload} = comp.serverFetch;
 dispatch({type, payload});           

使用

git clone https://github.com/zedwang/react-ssr-startkit.git
cd react-ssr-startkit
npm install
npm start           

继续阅读