Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Untyped auto generated hooks from RTK #1177

Open
OkuruchiDan opened this issue Jul 18, 2024 · 1 comment
Open

Untyped auto generated hooks from RTK #1177

OkuruchiDan opened this issue Jul 18, 2024 · 1 comment

Comments

@OkuruchiDan
Copy link

###The Problem:

When you creating an api slice using createApi method from rtk(specific version for react import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react') it's dose not provide any hook for export from api slice.

##Steps to reproduce:

Clone this repo, add example code from rtk with pockemon api.

// Need to use the React-specific entry point to allow generating React hooks
import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react'
import type { Pokemon } from './types'

// Define a service using a base URL and expected endpoints
export const pokemonApi = createApi({
  reducerPath: 'pokemonApi',
  baseQuery: fetchBaseQuery({ baseUrl: 'https://pokeapi.co/api/v2/' }),
  endpoints: (builder) => ({
    getPokemonByName: builder.query<Pokemon, string>({
      query: (name) => `pokemon/${name}`,
    }),
  }),
})

// Export hooks for usage in function components, which are
// auto-generated based on the defined endpoints
export const { useGetPokemonByNameQuery } = pokemonApi

Try to export useGetPokemonByNameQuery and you will see that it's type is any

As I understood after research, it's because of vite version.

Dose someone know how to fix this?

@ryota-murakami
Copy link
Contributor

@OkuruchiDan Thanks for reporting this! I'll look into it within three days!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants