0

I am new to RTK and RTK query. I am trying to set up initial configuration using the official documentation.

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}`,
    }),
  }),
})

The official docs didn't suggest how can i set initial state here

I tried passing initialState as the first argument

export const pokemonApi = createApi({
    initialState,
    reducerPath: "pokemonApi",
    baseQuery: fetchBaseQuery({ baseUrl: "https://pokeapi.co/api/v2/" }),
    endpoints: (builder) => ({
        getPokemonByName: builder.query<Pokemon, string>({
            query: (name) => `pokemon/${name}`,
        }),
    }),
});

This code leads to the following error:

Object literal may only specify known properties, and 'initialState' does not exist in type 'CreateApiOptions<BaseQueryFn<string | FetchArgs, unknown, FetchBaseQueryError, {}, FetchBaseQueryMeta>, { getPokemonByName: QueryDefinition<...>; }, "pokemonApi", never>'

How exactly can I set the initial state RTK query?

1 Answers1

0

You don't. The purpose of RTK Query is to fetch data from a server. It doesn't have an "initial state".

phry
  • 35,762
  • 5
  • 67
  • 81