When I try to use next/image<Image fill /> instead of <img /> the carousel component won't load that image. Though this seems to be only the case with some images/ in some situations.
Steps to reproduce:
Required packages: next. sharp, react,
copy paste the Carousel Custom Navigation code from the carousel docs with "use client" in L1
Download the image files, move them to some local folder and import them
Replace <img /> with Next's <Image /> and add the fill (fill={true}) option to all three images
the carousel is either completely invisible or can't load/hides the images with fill=true option
There are some variations too where I set img2 to fill=false and img1 was able to load but img3 wasn't (see carousel.tsx and second carousel.tsx code)
code:
app/layout.tsx:
import type {ReactNode, JSX} from "react";
import type {Metadata} from 'next';
import { Open_Sans } from 'next/font/google';
import {NextFont} from 'next/dist/compiled/@next/font';
import {cn} from '../lib/utils';
import './globals.css';
const inter: NextFont = Open_Sans({
subsets: ['latin']
});
export const metadata: Metadata = {
title: 'Test'
}
export default function RootLayout({children}: {children: ReactNode}): JSX.Element {
return (
<html lang="en">
<body className={cn(
inter.className,
"bg-black"
)}>
{children}
</body>
</html>
)
}
app/page.tsx
import {JSX} from "react";
import {Carousel} from "../components/carousel";
export default function Page(): JSX.Element {
return (
<Carousel />
);
}
When I try to use next/image
<Image fill />
instead of<img />
the carousel component won't load that image. Though this seems to be only the case with some images/ in some situations.Steps to reproduce: Required packages:
next
.sharp
,react
,Carousel Custom Navigation
code from the carousel docs with "use client" in L1<img />
with Next's<Image />
and add thefill
(fill={true}
) option to all three imagesfill=true
optionThere are some variations too where I set img2 to
fill=false
and img1 was able to load but img3 wasn't (see carousel.tsx and second carousel.tsx code)code:
app/layout.tsx
:app/page.tsx
components/carousel.tsx
carousel.tsx
only img3 doesn't load: