associationsreduxrelationships

How to set up associations with data in redux store


I'm using redux with an api middleware similar to the one here, which normalizes response data and stores the results in the entity field of my state. So, if I made a request to the customers endpoint and it returned something like:

customers: [{
  id: 1,
  name: 'Bob',
  cards: [{id: 2, last4: '1234'}]
}]

My store would look like:

{
  entities: {
    cards: {2: {id: 2, last4: '1234'}}
    customers: {1: {id: 1, name: 'Bob'}}
  }
}

My question is, what is the best way to set up these associations again? Could this be done with a selector?


Solution

  • I found this library which makes it very easy to deal with related data in your redux store. redux-orm