Reputation: 26124
I would like to save a function (reference) to my Redux store so that I can:
The general consensus seems to be that you should not store function references in the Redux store (because the data should be serializable). Are there any ways to get around this so that the above two processes can be realised?
Upvotes: 3
Views: 5211
Reputation: 67607
Per the Redux FAQ entry on non-serializable items in 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.
Upvotes: 3