剧场模式
首页前端Redux轻松学 Redux-Saga

轻松学 Redux-Saga #2 准备环境和安装 Redux

想卖咖啡的程序员 · 真仙发布于
5

$ yarn add redux react-redux
$ yarn add --dev redux-devtools-extension

src/index.js

import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
import registerServiceWorker from './registerServiceWorker';

import { createStore } from 'redux';
import rootReducer from './reducers';
import { composeWithDevTools } from 'redux-devtools-extension';

import { Provider } from 'react-redux';

const store = createStore(
  rootReducer,
  composeWithDevTools()
)

ReactDOM.render(
  <Provider store={ store }>
    <App />
  </Provider>,
  document.getElementById('root')
);

registerServiceWorker();

src/reducers/index.js

import { combineReducers } from 'redux';

import users from './users';

export default combineReducers({
  users
});

src/reducers/users.js

const users = (state = {}, action = {}) => {
  switch(action.type) {
    default: return state;
  }
}

export default users;
4 条回复

© 汕尾市求知科技有限公司 | 粤ICP备19038915号 | 在线学员:88

Top