RTK query hook, entities as array #3813
Replies: 1 comment 7 replies
-
Out of curiosity, what's the actual need to normalize the entities in that endpoint? You can certainly do it (and I even showed how in the "Essentials" tutorial) - just wondering what the use case is here. Beyond that, yeah, |
Beta Was this translation helpful? Give feedback.
7 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I'm fairly new to RTK Query and constantly learning how to use it and be more efficient. I have an apiSlice that normalizes the data. When I use the query hook in my component and console log the data, I can see that it's normalized. Is there a way in the hook to only return the entities as an array? I know there's the selectFromResult function that can get a single item by using an id to find the right item, but in this case I need the all of the entities as an array so I can map over them. So far I've got it down to
But this seems less efficient as compared to
Here's my apiSlice
I'm not sure it matters, but I do have a Prefetch wrapper that tries to prefetch the data
I'll expand this out to more apiSlices once I understand fully what I'm doing here. Is there any reason to use the query hook to get all items vs just using the selector? I'm I missing something here? I've read the documents as best as I can...they sometimes go over my head. But I know I'm on the right path, just not sure what's the best way forward.
Beta Was this translation helpful? Give feedback.
All reactions