score:0

this type of question probably belongs at https://codereview.stackexchange.com/.

with that said. my suggestion. split it up into two reducers and combine them with combinereducer for a cleaner way. it makes more sence to have a single "updateable" (immutable) object as root.

my suggestion would then be:

companies: [{
    name: "google"
 }];

persons: {
    "google": {
        1: { name: "john" }, 
        2: { name: "erica" }
     }
};

if you need a key, or else feel free to use array as persons. i have always though maps makes better state objects and object.keys can be easily used to iterate through them later.

or you can ofcouse use your "method no 1" with a array of keys if that fits your backend and data structure better.

score:4

you should consider using a normalizing state shape for your store in redux.

using this approach i would suggest you to use your first approach where i suppose you keep separate various entities, like persons and companies, and linkt theme together using an id.

// first way
persons: {
    1: {
       name: "john",
    },
    2: {
       name: "erica",
    }
 };

 companies: [{
    name: "google",
    persons: [1, 2]
 }];

Related Query

More Query from same tag