O
O
OliverAlt2019-06-03 20:51:52
JavaScript
OliverAlt, 2019-06-03 20:51:52

How to save an object in the redax store?

In the reducer, xhr outputs an xhr object, file outputs a file object, but the resulting state contains only empty objects. Where is the mistake?

[fileId]: {
    file: {},
    loading: true,
    progress: 0,
    xhr: {},
},

UPLOAD_FILE_REQUEST(state, payload) {
        const {
            contactIndex,
            fileId,
            file,
            xhr,
        } = payload;

        return {
            ...state,
            contacts: state.contacts.map((contact, index) => {
                if (index === contactIndex) {
                    console.log('-->', payload); // здесь payload.xhr выводит объект xhr, file - объект file
                    return {
                        ...contact,
                        draft: {
                            ...contact.draft,
                            files: {
                                ...contact.draft.files,
                                [fileId]: {
                                    file,
                                    loading: true,
                                    progress: 0,
                                    xhr,
                                },
                            },
                        },
                    };
                }
                return contact;
            }),
        };
    },

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nikita, 2019-06-04
@thewitcher123

Have you considered the immutable package for working with the store?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question