0

Login这是我的组件选择器文件

import { createSelector } from 'reselect';
const authentication = () => (state) => state.get('login');
const getCurrentAuthData = () => createSelector(
  authentication,
  (loginState) => loginState.get('currentUser')
);
export {
  authentication,
  getCurrentAuthData,
}; 

这是描述Login组件状态的reducer文件

import { fromJS } from 'immutable';
import { loginConstants } from './constant';

let user = JSON.parse(localStorage.getItem('user'));
const initialState = user ? fromJS({ loggedIn: true, user }) : fromJS({});

function loginReducer(state = initialState, action) {
   switch (action.type) {
   case loginConstants.LOGIN_REQUEST:
       return state
          .set('loggingIn', true)
          .set('user', action.true)
   case loginConstants.LOGIN_SUCCESS:
       return state
          .set('loggedIn', true)
          .set('user', action.true)
  case loginConstants.LOGIN_FAILURE:
       return fromJS({});
  case loginConstants.LOGOUT_REQUEST:
       return fromJS({});
  case loginConstants.LOGOUT_SUCCESS:
       return fromJS({});
  case loginConstants.LOGOUT_FAILURE:
       return fromJS({});
  default:
       return state
  } 
 }

 export default loginReducer;

现在的问题是它给出了错误,因为 loginState.get 不是一个函数。

PS 我引用了 React-boilerplate [ https://github.com/react-boilerplate/react-boilerplate]的代码,基本上是复制粘贴代码(学习阶段)。

4

1 回答 1

0

问题解决了,不出所料,写语句有误。我将声明从

const authentication = () => (state) => state.get('login');
//here it is returning a function to authentication

const authentication = (state) => state.get('login');
//here it is returning `state.get('login')` to authentication
于 2018-02-12T12:48:51.153 回答