0
votes

My Reducer

export default function saveContactsReducer(state = {}, { type, contacts }) {
switch (type) {
    case types.SAVE_CONTACTS:
        return {
            ...state,
            contactsDetails: contacts,
            currentUserName: contacts.personName
        }
    default:
        return state;

}

}

My Action

import * as types from './actionTypes';

function saveContacts(contacts) {
    return { type: types.SAVE_CONTACTS, contacts: contacts }
}

export default saveContacts;

My Action dispatch

 dispatch(contactsAction(contactsDetails));

When I am using the useSelector hook from the react-redux

My state is like this

state.saveContactsReducer: {contacts}}

Instead I want state.contacts and don't want reducer name

1

1 Answers

0
votes

Actually, the problem was the root reducer where I had passed all the reducers with their name. which I changed to the key which I wanted something like this.

Earliter it was like this

const rootReducer = combineReducers({
  contactsReducer,
});

To fix changed the reducer name to the key which I wanted.

const rootReducer = combineReducers({
      contacts,
    });