Let's say you have a book application using Redux with a few features:
- Buy books
- Have a wishlist of books
- Maintain a list of books you own
- Send recommendations to friends
- Review books
Now let's say that all of these different modules, and a common feature across all these modules is the ability to search for books (i.e. searching for books to buy, books to add to a wishlist, books to review, etc).
These search results will be stored across multiple slices of the state tree.
An example of the state tree might look like this:
{
bookStore: {
booksSearchResults: [],
...,
},
wishlist: {
booksSearchResults: [],
...,
},
reviews: {
newReview: {
booksSearchResults: [],
...,
},
...
},
...
}
Are there any best practices around managing such things? Would it be simply to have a booksSearch
slice of state and manage that through a shared component?
How about cases where you might need to search for books in multiple places on the same screen (i.e. you might have an autocomplete search feature in the nav bar in addition to a search component in the main part of the application)?
Is another approach to reuse the search logic and somehow have it update different parts of the state (and if so, does something exist to achieve this)?