An example of using createEntityAdapter and RTK Query without using endpoints.endpoint.select #3026
Replies: 2 comments 6 replies
-
The point of Looking at your code: my first suggestion would be to finish updating the naming so that it's no longer The second issue is that Next, as a sorta different issue: you shouldn't be supplying TypeScript generic args to In general, what you probably need is to do this inside the component: const selectAllDashboardShares = useMemo(() => {
const selectDashboardCacheEntry = someApi.endpoints.getDashboardShares.select(dashboardId);
const { selectAll } = dashboardAdapter.getSelectors();
return createSelector(
(state) => selectDashboardCacheEntry(state)?.data,
(cacheData) => {
return cacheData ? selectAll(cacheData) ?? initialState
}
)
}, [dashboardId]) In other words:
|
Beta Was this translation helpful? Give feedback.
-
What is your intent in combining these two? Are you aware that adding an entityAdapter will still keep all your cache entries separate from each other? |
Beta Was this translation helpful? Give feedback.
-
I'm wondering if it's possible to add an example of using createEntityAdapter and RTK Query without using
endpoints.endpoint.select
?I've been doing a POC with RTK Query in our app.
Everything's been great until I've tried using createEntityAdapter.
I've followed the advanced pattern docs, but no matter what, my selector return nothing.
The docs seem confusing on to properly handle this.
I just want to use the
selectAll
selector from the adapter so do I need to actually pass anything tousersAdapter.getSelectors()
?I saw in an StackOverflow post that I shouldn't even need to user
endpoints.getUsers.select(null);
right?I can't find an example in the code of how to not use that, and I can't get to work when I have to use it.
I didn't see any typescript implementation of this, so it's possible one of my assumptions broke it.
Could it be that I'm not directly calling:
store.dispatch(extendedApiSlice.endpoints.getUsers.initiate());
? Instead I'm just using the hook? It's my understanding that I shouldn't need to do all these manuel steps right?Here is my code. I've copied the code straight from the docs, and updated it to hit my endpoint (/dashboards/${dashboardId}/shares)
My Slice, the only thing different from the docs is my query path
The main api
The App. Data is correct, but dashboardShares is empty.
Beta Was this translation helpful? Give feedback.
All reactions