Does it work with RTK-Query? #18
Replies: 3 comments 4 replies
-
Lol yup. You just need to be clear about what it is actually DOING. Take a look at the default supported types. We aren't sending unserializable types to the store. Instead, we're converting those types into objects that ARE serializable, and then storing THOSE. Then we reverse the process on the way out. So the get the EFFECT of storing unserializable types without actually having to do so or think about it too hard. One caveat: the middleware performs the |
Beta Was this translation helpful? Give feedback.
-
The trouble with Redux middleware (ahem @markerikson) is that it only runs on the way in. That's why it only works on Honestly I don't think you will have an issue here. Just run Admittedly it isn't a perfect solution but I had a pretty data-heavy application and it did the trick just fine for me. And if you feel like rolling up your sleeves, I'm totally open to input. :) One thing worth mentioning: the process is recursive in both directions. So you really only need to run it at the top level. |
Beta Was this translation helpful? Give feedback.
-
Just a taste... here's a usage example with // Get selected game index (a BigInt).
const selectedGameIndex = deserify(
useSelector((state) => state.page.selectedGameIndex, blockRefresh)
); How did that It really is that simple. Also, if you're storing structured data in Redux and you haven't looked at blockRefresh, you should. Keeping in mind that a serified value (assuming it required serification) is structured data by definition. 😎👊 |
Beta Was this translation helpful? Give feedback.
-
Just chuck the middleware between RTK-Query'd middleware and the store and poof, we can store natively unserializable data? Have you tried it?
I guess there would be some issues with the serialization for the cache key but that's fixable.
Beta Was this translation helpful? Give feedback.
All reactions