Home > database >  Problem with my first Redux Toolkit exercises
Problem with my first Redux Toolkit exercises

Time:12-13

I am new to coding and I am trying to learn redux toolkit but I don't succeed in fetching data from PokeAPI.

I wanted to retrieve data from PokeAPI but the query I am doing is rejected and I can't figure out why. In my DevTools for Redux I see "executeQuery/rejected". I've also pushed the full code to my repo on GitHub: https://github.com/LittleWing85/Playground_Redux-Toolkit and I would be really thankful for your hints!

This is the part of my code where I do the query and in the UI I can see "Oh no, there was an error":

import { useGetPokemonByNameQuery } from "../../app/pokemon_Api";

export function Pokemon() {
    const { data, error, isLoading } = useGetPokemonByNameQuery("bulbasaur");
    return (
        <div className="App">
            {error ? (
                <>Oh no, there was an error</>
            ) : isLoading ? (
                <>Loading...</>
            ) : data ? (
                <>
                    <h3>{data.species.name}</h3>
                    <img
                        src={data.sprites.front_shiny}
                        alt={data.species.name}
                    />
                </>
            ) : null}
        </div>
    );
}

CodePudding user response:

In the file src/app/pokemon_Api.js, you have an extra ' in the beginning of the baseUrl passed to the fetchBaseQuery config. Removing that fixes the issue.

  • Related