This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
Question: Rtk Endpoint Hook Called In Component Loop #4710
Labels
You can continue the conversation there. Go to discussion →
Hi folks! I have an RTK question, hope this is the right place to ask it. I've got an RTK endpoint definition that looks something like:
I have a react component that allows you to select/deselect multiple customers. Select/Deselect/Bulk Select/Bulk Deselect.
Its works well with the above RTK definition, using something like this in the component:
The problem is, the caching isn't working well.
E.g. if you select all customers, it makes a query/cache entry for:
And lets say I deselect a single customer (e.g. customer 123), then this query is made:
So another query, and another cache entry with data that all was already fetched.
I've been trying to get this excessive query/caching to be better, but am struggling. I keep thinking there must be a way this is supposed to be done with RTK but I can't find anything!
Any pointers would be very much appreciated!
Some things I've thought of doing but either can't or it's really ugly:
/customers?driverId=???
for 1 driver at a time, in a loop, but I can't use the hook inside a loop in the component.queryFn
instead ofquery
in RTK, where I can check the endpoint state. But then handling invalidation is impossible (unless I'm missing something, I don't see any invalidating state in the rtk state)The text was updated successfully, but these errors were encountered: