Skip to content

[RTK-Query] Accessing data and statuses from other components the redux way #1254

@shubhamdeodia

Description

@shubhamdeodia

From the documentation, it is not clear how I can access data the which was fetched from the RTK query.

I have a like below

export const apiSlice= createApi({
    reducerPath: 'api',
    baseQuery: fetchBaseQuery({
        baseUrl: 'url'
    }),
    endpoints: (builder) => ({
        fetchData: builder.query({
            query: () => ({
                url: `/api/`,
                method: 'GET',
            })
        })
    })
});

export const { useFetchDataQuery} = apiSlice;

Now this API slice fetch the data and show the different states like isLoading, isFeteching when I use it like this in some component

const { data, isLoading, isFetching } = useFetchDataQuery();

What I really want to ask is, How can I access the same data (which is fetched in the above query) using selectors in any other component, rather than passing the data as props?

Since the data is getting stored in redux only. I was hoping to access it in a simple way like using useSelectors

Also, do we have anything like useIsFetching() like there is in react-query?

Metadata

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