这是我Login
组件
import { createSelector } from 'reselect';
const authentication = () => (state) => state.get('login');
const getCurrentAuthData = () => createSelector(
authentication,
(loginState) => loginState.get('currentUser')
);
export {
authentication,
getCurrentAuthData,
};
这是reducer文件,它描述了Login
组件
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]代码,基本上是复制粘贴代码(学习阶段)。
答案 0 :(得分: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