I am trying to return an image carousel component from daisyUI but whenever I try to use it in the return statement in my App.tsx it returns an error, but doesn't whenever there is just one component (Navbar). The error message states
'ImageSlides' cannot be used as a JSX component.
Its return type 'void' is not a valid JSX element.
in App.tsx
import { useState } from "react";
import "./App.css";
import { NavBar } from "./components/NavBar";
import { ImageSlides } from "./components/ImageSlides";
const App = () => {
return (
<div className="App">
<NavBar />
<ImageSlides/>
</div>
);
};
export default App;
in ImageSlider.tsx
import React from "react";
export function ImageSlides () {
<div className="carousel w-full">
<div id="slide1" className="carousel-item relative w-full">
<img src="https://placeimg.com/800/200/arch" className="w-full" />
<div className="absolute flex justify-between transform -translate-y-1/2 left-5 right-5 top-1/2">
<a href="#slide4" className="btn btn-circle">❮</a>
<a href="#slide2" className="btn btn-circle">❯</a>
</div>
</div>
<div id="slide2" className="carousel-item relative w-full">
<img src="https://placeimg.com/800/200/arch" className="w-full" />
<div className="absolute flex justify-between transform -translate-y-1/2 left-5 right-5 top-1/2">
<a href="#slide1" className="btn btn-circle">❮</a>
<a href="#slide3" className="btn btn-circle">❯</a>
</div>
</div>
<div id="slide3" className="carousel-item relative w-full">
<img src="https://placeimg.com/800/200/arch" className="w-full" />
<div className="absolute flex justify-between transform -translate-y-1/2 left-5 right-5 top-1/2">
<a href="#slide2" className="btn btn-circle">❮</a>
<a href="#slide4" className="btn btn-circle">❯</a>
</div>
</div>
<div id="slide4" className="carousel-item relative w-full">
<img src="https://placeimg.com/800/200/arch" className="w-full" />
<div className="absolute flex justify-between transform -translate-y-1/2 left-5 right-5 top-1/2">
<a href="#slide3" className="btn btn-circle">❮</a>
<a href="#slide1" className="btn btn-circle">❯</a>
</div>
</div>
</div>
}
I tried adding the code inside of ImageSlide into App.tsx to see if there was any errors in the code it self. it worked so it seems like the only probably is trying to import ImageSlide into App.tsx.
CodePudding user response:
Your ImageSlider.tsx
is omitting a return
statement. Your functional component is not actually returning anything.
CodePudding user response:
you need to return the JSX code, return value is VOID.
import React from "react";
export function ImageSlides () {
return ( <div className="carousel w-full">
<div id="slide1" className="carousel-item relative w-full">
<img src="https://placeimg.com/800/200/arch" className="w-full" />
<div className="absolute flex justify-between transform -translate-y-1/2 left-5 right-5 top-1/2">
<a href="#slide4" className="btn btn-circle">❮</a>
<a href="#slide2" className="btn btn-circle">❯</a>
</div>
</div>
<div id="slide2" className="carousel-item relative w-full">
<img src="https://placeimg.com/800/200/arch" className="w-full" />
<div className="absolute flex justify-between transform -translate-y-1/2 left-5 right-5 top-1/2">
<a href="#slide1" className="btn btn-circle">❮</a>
<a href="#slide3" className="btn btn-circle">❯</a>
</div>
</div>
<div id="slide3" className="carousel-item relative w-full">
<img src="https://placeimg.com/800/200/arch" className="w-full" />
<div className="absolute flex justify-between transform -translate-y-1/2 left-5 right-5 top-1/2">
<a href="#slide2" className="btn btn-circle">❮</a>
<a href="#slide4" className="btn btn-circle">❯</a>
</div>
</div>
<div id="slide4" className="carousel-item relative w-full">
<img src="https://placeimg.com/800/200/arch" className="w-full" />
<div className="absolute flex justify-between transform -translate-y-1/2 left-5 right-5 top-1/2">
<a href="#slide3" className="btn btn-circle">❮</a>
<a href="#slide1" className="btn btn-circle">❯</a>
</div>
</div>
</div>);
};