DEV Community

DragonFruit
DragonFruit

Posted on

Images not appearing in CardContainer components

I'm facing an issue with my React application where the images inside my CardContainer components are not appearing on the page. The CardContainer components themselves are rendering properly, and the styling is being applied correctly. However, both the default images and the hover images generated by the getHoverImg function are not showing up.

Here's the relevant code snippet:

import React from 'react';
import { useParams } from 'react-router-dom';
import "./CardCollection.css";
import TopNavbar from "../Index/IndexPageComponents/TopNavbar/TopNavbar.jsx";
import SuccessStory from '../Index/IndexPageComponents/SuccessStory/SuccessStory.jsx';
import ContactNavbar from '../Index/IndexPageComponents/ContactNavbar/ContactNavbar.jsx';
import BottomNavbar from '../Index/IndexPageComponents/BottomNavbar/BottomNavbar.jsx';
import CardContainer from '../Introduction/TarotIntroductionComponents/CardContainer/CardContainer.jsx';
import TextContainer from '../Index/IndexPageComponents/TextContainer/TextContainer';

export default function CardCollection() {
const { cardsName } = useParams();

const getHoverImg = (defaultImg, hoverImg) => {
    return hoverImg ? hoverImg : defaultImg.replace('.jpg', '-hover.jpg');
};

// Data for each Tarot card
const collectionCardData = {
    'major-arcana': [
        // Card data here
    ],
    'minor-arcana': [
        // Card data here
    ],
};

const cardData = collectionCardData[cardsName];

if (!cardData) {
    return <div>Card data not found</div>;
}

return (
    <div className='background_image'>
        <TopNavbar />
        <TextContainer 
            title={cardsName} // Assuming you want to display the category name as title
        />
        <div className='card-container-wrapper-major-arcana'>
            {cardData.map((card, index) => (
                <CardContainer
                    key={index}
                    img={card.img}
                    hoverImg={card.hoverImg}
                    link={card.link}
                />
            ))}
        </div>

        <div className="success-story-box-container">
            <SuccessStory />
            <SuccessStory />
            <SuccessStory />
        </div>
        <ContactNavbar />
        <div className="success-story-box-container">
            <SuccessStory />
            <SuccessStory />
            <SuccessStory />
        </div>
        <BottomNavbar />
    </div>
);
Enter fullscreen mode Exit fullscreen mode

}

I've verified that the image paths and hover image paths are correct, and the getHoverImg function is working as expected. However, the images are still not appearing on the page.

(I am using the same images in another component, and there they are rendering, so it has nothing to do with the file names or existence)

Top comments (0)