1

i just started to write code in redux and am facing some issues while getting value from redux store

browse-upload.js

const initialState = {
    modal: false
};

const browseUploadReducer = (state = initialState, action) => {
    switch (action.type) {
        case GET_MODAL_INFORMATION: {
            return {
                ...state,
                modal: true
            };
        }
        case GET_CLOSE_MODAL_INFORMATION: {
            return {
                ...state,
                modal: false
            };
        }
        default:
            return state;
            break;
    }
};

export const getModalOpen = () => (dispatch) => {
    dispatch({
        type: GET_MODAL_INFORMATION
    });
};

export const getModalClose = () => (dispatch) => {
    dispatch({
        type: GET_CLOSE_MODAL_INFORMATION
    });
};

export default browseUploadReducer;

and in my component , i just tried to retrieve the value from store

import { getModalOpen,getModalClose} from 'reducers/star/browse-upload';

const mapStateToProps = state => ({
    modal: state.modal,
});

what might went wrong ?Still control not coming back to component? How can i verify that?

5
  • Can you share your root reducer file? Commented Feb 6, 2020 at 6:30
  • have you added browseUploadReducer to your combineReducer function. Commented Feb 6, 2020 at 6:31
  • Can you share the complete error stack trace? Thanks Commented Feb 6, 2020 at 6:44
  • 2
    Can you try this: const mapStateToProps = state => ({ modal: state.modal }); Commented Feb 6, 2020 at 6:47
  • 2
    if you console your state.browseUpload its undefined. therefore, you are getting undefine.modal where as undefined is not an object. so, first you should get an object or a value in state.browseUpload Commented Feb 6, 2020 at 7:02

1 Answer 1

3

In your mapStateToProps, write this:

const mapStateToProps = state => ({ modal: state.modal });

I think issue is; there is no such thing called browseUpload defined in your state that is why you are getting the error.

Sign up to request clarification or add additional context in comments.

3 Comments

, am not getting back modal value const browseUploadReducer = (state = initialState, action) => { switch (action.type) { case GET_ASSETS_LIST: { return { ...state, modal:true, currentSection:action.payload }; } default: return state; } };
@muhammad Zeeshan i can see control in my reducer ,but i guess its not coming back to my component, also am not getting value in const mapStateToProps = state => ({ modal: state.modal }); based on this am taking modal value in render and trying to console,its not showing
Can you share the code where you are trying to get the value of modal and also update the complete reducer file code?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.