Search code examples
typescriptredux-toolkitrtk-query

how to export query after injectEndpoints


export const emptySplitApi = createApi({
    baseQuery: fetchBaseQuery({ baseUrl: '/' }),
    endpoints: () => ({}),
})


const extendedApi = emptySplitApi.injectEndpoints({
    endpoints: (build) => ({
        example: build.query({
            query: () => 'test',
        }),
    }),
    overrideExisting: false,
})

export const { useExampleQuery } = extendedApi

despite the fact that the code is copied from the official documentation TS throw this error TS2339: Property 'useExampleQuery' does not exist on type 'Api , { example: QueryDefinition ...>, never, any, "api">; }, "api", never, unique symbol>'


Solution

  • You likely did not import from the react bundle, so you do not get hooks generated.

    Please make sure that you import { createApi } from "@reduxjs/toolkit/query/react - the /react is essential.