Building A Blog By React Ecosystem(3)

It's time to add Redux to our project.

Even though we have typed so many codes but our web page shows nothing, don't worry , It's necessary to build a great project . After the scaffolding finished , we can create everything immediately .

Our index.js like that :

import React from 'react';
import { render } from 'react-dom';
import { Provider } from 'react-redux';
import { browserHistory } from 'react-router';
import configureStore from './store';
import createRoutes from './routes';

const store = configureStore();

render((
  <Provider store={store}>
    {createRoutes(browserHistory)}
  </Provider>
),

document.getElementById('app'));

You can find from those codes that we need reducers and configureStore right?
So our work is created them.

./store/index.js


import { createStore, applyMiddleware } from 'redux';
import rootReducer from '../reducers';

const createStoreWithMiddleware = applyMiddleware()(createStore);

export default function configureStore(initialState = {}) {
  const store = createStoreWithMiddleware(rootReducer, initialState);

  if (module.hot) {
    module.hot.accept('../reducers', () => {
      const nextRootReducer = require('../reducers'); // eslint-disable-line global-require
      store.replaceReducer(nextRootReducer);
    });
  }
}

It 's a function to create a store with some middlewares (now we have no any middlewares, but then we have ), and put the reducers together by rootReducer.
and when we use hot-loader it can auto fresh the reducers functions.

And we need reducers .

./reudcers/index.js

import { combineReducers } from 'redux';

const rootReducer = combineReducers(
  {}
);

export default rootReducer;

It holds nothing now. How we check it works?
We can find react-devtool from Chrome Plugins Store.
Using it we can easily confirm them work .

Next part we will create styles for app.

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 文/ 杨维玉 羲和弟, 你好。 昨日中央经济会议闭幕,部里事情便多了些,这些天没有收到你的回复,听伯父说,是一直在...
    羲和阅读 1,147评论 0 1
  • 看到Newton参加了坚持晨间写作的活动,很感兴趣。坚持写作其实蛮难的,坚持晨间写作,对爱睡懒觉的我来说就更难了...
    清晨微露阅读 237评论 0 0
  • 1. 今日,许久未见的三个好友相聚。在必胜客点个下午茶,便聊了几个小时的青春记忆。 那一段纯粹的青葱时光带来了多少...
    如此且行阅读 334评论 1 5
  • 说玩法轻松了点,我想给自己一个新的挑战,每天花15分钟时间记录今天最有意义的学习成果,思考和挑战。一是让自己把每天...
    正宗毛利大五郎阅读 180评论 0 1