Access to Multiple Nested Data Entities in Database

Learn how to access multiple nested entries.

Getting a list of favorite recipes is also much simpler with a normalized state, as we only need to scan the recipes “table.” This can be done in the UI using a function called a selector. If you think of the state as a database, you can imagine selectors as database queries:

//import filter from lodash/filter package
import filter from 'lodash/filter';

const getFavorites = (state) =>
  filter(state.recipes, 'favorite');

The main improvement is that we do not need to be aware of the structure or nesting of the state to access deeply nested information. Instead, we should treat our state as a conventional database from which to extract data for the UI.

Get hands-on with 1200+ tech skills courses.