0

this is my selector file for Login component

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

and this is the reducer file which describes the state for Login component

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;

Now the problem is it's giving error as loginState.get is not a function.

PS I am referencing the React-boilerplate [https://github.com/react-boilerplate/react-boilerplate] for code and basically copy-pasting code (learning phase).

Tripti Rawat
  • 645
  • 7
  • 19
  • I think you should look at this doc : https://redux.js.org/docs/recipes/UsingImmutableJS.html – Vishal Sharma Feb 12 '18 at 12:03
  • 1
    Already had looked into it but to no success. BUT the problem has been solved. What I did was change the statement const authentication = () => (state) => state.get('login'); TO const authentication = (state) => state.get('login'); [I had put an extra ()=>] – Tripti Rawat Feb 12 '18 at 12:23

1 Answers1

0

The problem is solved, as expected there was in error in writing the statement. I changed the statement from

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

to

const authentication = (state) => state.get('login');
//here it is returning `state.get('login')` to authentication
Tripti Rawat
  • 645
  • 7
  • 19