score:2

Accepted answer
const nullcustomerentities = {
    customer: "anonymous"
}

export const getselectedcustomer = state => state.systems.selectedcustomer;

export const getcustomerentities = state => {
    return state.systems.entities[getselectedcustomer(state)] || nullcustomerentities;
}

export const getselectedcustomername = state => {
    return getcustomerentities(state).customer;
}

this is a classic example of a null object pattern (hope you don't mind the code being in ruby).


Related Query

More Query from same tag