Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Problem with my first Redux Toolkit exercises

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":

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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>
    );
}

>Solution :

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading