When reading the redux doc I found that the doc mentioned this:
Still, you should do your best to keep the state serializable. Don\'t put anything
Adding to what @Timo said , If you want to setup relation between 2 states in your state tree and use computed values, reselect
is the best suitable fit for that scenario. It allows to creareselectors
which can be used to define computed states. In your case author
can be created using a selector on top of book
. https://github.com/reactjs/reselect
Directly from the redux FAQs:
Can I put functions, promises, or other non-serializable items in my store state?
It is highly recommended that you only put plain serializable objects, arrays, and primitives into your store. It's technically possible to insert non-serializable items into the store, but doing so can break the ability to persist and rehydrate the contents of a store, as well as interfere with time-travel debugging.
If you are okay with things like persistence and time-travel debugging potentially not working as intended, then you are totally welcome to put non-serializable items into your Redux store. Ultimately, it's your application, and how you implement it is up to you. As with many other things about Redux, just be sure you understand what tradeoffs are involved.
Further reading:
@timo 's answer is correct. In addition, I recommend a library called Redux-ORM to work with normalized/relational data in your Redux store. See my recent comment at Dealing with data consistency in a very large store in React + Redux SPA SaaS for links to more information.