Accessing nested object returns empty array

269 Views Asked by At

I'm retrieving data from api and storing it in a sharedState. When i'm trying to access this data like below it seems to return the correct. There is one object in the dashboard array with name field.

console.log(newState.profile)

returns:

enter image description here

However when i access dashboards

console.log(newState.profile.dashboards)

it returns

[]

function to set the state from main.js

export function getProfile(state, user) {
    const newState = Object.assign({}, state);

    if (user) {
        db().collection("users").doc(user.uid)
            .onSnapshot((doc) => {
                var data = doc.data()

                if (data) {
                    newState.profile.apps = data.apps
                    newState.profile.dashboards = data.dashboards
                } else {
                    authservice.setUserAcc(user.uid)
                }

            });
    }
    return newState
}

i'm not sure wether this is a javascript behaviour or related to the way i did set up the state.

0

There are 0 best solutions below