Skip to content

RTK Query and createEntityAdapter gap #4579

Closed

Description

This is mostly a question to be honest... I've been going through the docs learning about RTK and everything is pretty much clear with nice examples. You create a query or mutation, and these can be triggered using the autogenerated hooks in components like so:
https://redux.js.org/tutorials/essentials/part-7-rtk-query-basics#using-query-hooks-in-components
const { data: posts = [], isLoading, isSuccess, isError, error } = useGetPostsQuery()
Later, at RTK Query advanced patterns we learn that we can still use createEntityAdapter to manage normalized data:
https://redux.js.org/tutorials/essentials/part-8-rtk-query-advanced#transforming-responses
and we can use
export const { selectAll: selectAllUsers, selectById: selectUserById } = usersAdapter.getSelectors(selectUsersData)
to start using selectors of our entity.

What is not clear to me is how we use the normalized data in our components? Do I convert the above to:

const { isLoading, isSuccess, isError, error } = useGetPostsQuery(); const posts = useSelector(selectAllPosts)
I guess the question is, do I stop using the data exposed by the generated query hook and start calling the selectors generated by the entity adapter? Or is there some kind of integration that I am missing which updates the data returned from the generated hook? I think I am mixing the concept of querying with normalization which are separate and I am guessing it makes sense to be kept this way.

Thanks for making our life easier :) Migrating from older redux version to RTK and we can already see the benefits and the boilerplate cutdown.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions