...

/

State as a Database

State as a Database

Learn how to resolve the issues in the previous lesson by treating the state as a database.

We'll cover the following...

A recommended approach to solving the various issues raised in the previous lessons is to treat the application state as a database of entities. Like in a regular table-based database, we will have a “table” for each entity type with a “row” for each entity. The entity id will be our “primary key” for each table.

In our example, we will break down nesting to make our state as shallow as possible and express connections using IDs:

const state = {
  books: {
    21: {
      id: 21,
      name: 'Breakfast',
      recipes: [63, 78, 221]
    }
 
...