react redux reducer无法设置fetch api数据来存储

时间:2018-06-11 21:32:59

标签: reactjs redux

我有这个代码请检查下面是否有这个问题,存储默认状态无法使用fetch api调用动作和reducer进行更新,如下所述

configstore.js

import { createStore, combineReducers, applyMiddleware } from 'redux';

import products from './views/Products/reducer';
import categories from './views/Categories/reducer';
import user from './views/Login/reducer';
import thunk from 'redux-thunk';
import { composeWithDevTools } from 'redux-devtools-extension';
import createHistory from 'history/createBrowserHistory';
import { routerMiddleware } from 'react-router-redux';

console.log(user);
const defaultState = {
  products: {
    items: [],
    isFetching: 0,
  },
  categories : {
    items: [],
    isFetching: 0,
  },
  user : {
    email:'',
    token:'',
    isLoggedIn:false
  }
};

const rootReducer = combineReducers({ 
  products,
  categories,
  user  
});


const store = createStore(
  rootReducer,  
  defaultState,
  composeWithDevTools(
  applyMiddleware(thunk))
);

export default store;

reducer文件包含基于不同状态键的切换条件

进口

 { LOGGIN_USER } from './actions';

const isLoggedIn = (state = [], action) => {
  switch (action.type) {
  case LOGGIN_USER:
  return Object.assign( {}, state, { user: action.payload.isLoggedIn } );
  default:
    return state;
  }
};

const email = (state = [], action) => {
    switch (action.type) {
    case LOGGIN_USER:
    return Object.assign( {}, state, { user: action.payload.email } );
    default:
      return state;
    }
  };

  const token = (state = [], action) => {
    switch (action.type) {
    case LOGGIN_USER:
    return Object.assign( {}, state, { user: action.payload.token } );
    default:
      return state;
    }
  };

  export default combineReducers({
    email,
    token,
    isLoggedIn
  });

动作文件     import'whatwg-fetch';     从'../../ config / config';

导入配置
export const REQUEST_PRODUCTS = 'REQUEST_PRODUCTS';
export const RECEIVE_PRODUCTS = 'RECEIVE_PRODUCTS';
export const LOGGIN_USER = 'LOGGIN_USER';

// export const loggOnUser = products => ({
//   type: LOGGIN_USER,
//   products,
// });

export const authenticateUser = ( auser ) => ({
  type: LOGGIN_USER,
  auser
});

please anyone needed help on this why store state with key 

user{
'email':''
'token':'',
'isLoggedIn':''
}

提前感谢任何帮助

0 个答案:

没有答案