Final tips and tricks
In the final section of this book, we will walk through some general tips and tricks that we need to keep in mind when we develop Redux applications:
- Designing the application state
- Updating application state
Designing the application state
In many applications, you will deal with nested or relational data. For example, our blog had posts--each post could have many comments, and both comments and posts are written by a user.
Using indices
We have already discussed this previously--you may prefer to store your data in objects with their database ID as the key, and the data entry as the value. Such an object is called an index, and structuring the state as an index makes it easy to select and update the data.
For example, we could store our posts as follows:
{ posts: { "post1": { id: "post1", author: "dan", text: "hello world", comments: ["comment1"] }, "post2": { ... }, ... } }
We can access a single post via state.posts[postId]
. Using...