gpt4 book ai didi

reactjs - React 应用程序在生产环境中出现 "Element type is invalid"错误,但正在开发中

转载 作者:行者123 更新时间:2023-12-05 03:29:34 29 4
gpt4 key购买 nike

在我的 React 应用程序中,使用 react-multi-carousel 时出现以下错误。但是,它只发生在 Google Firebase 托管上。它在本地运行良好。

我的项目是使用 Vite 和 Tailwind CSS 创建的。

错误:

Error: Minified React error #130; visit https://reactjs.org/docs/error-decoder.html?invariant=130&args[]=object&args[]= for the full message or use the non-minified dev environment for full errors and additional helpful warnings.

转化为:

Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object.

home.jsx

    import React, { useState, useEffect } from "react";
import { useQuery } from "@apollo/client";
import GitaCarousel from "../../components/gita_carousel";
import { getHome, getHomeVariable } from "../../gql/home";

const HomePage = () => {
const [artists, setArtists] = useState();

const { loading, error, data } = useQuery(getHome, {
variables: getHomeVariable(10),
});

useEffect(() => {
if (!loading && !error) {
const a1 = data?.artists.map((artist) => ({
id: artist.id,
title: artist.name,
subTitle: "",
imageUrl: artist.profile_picture,
}));
setArtists(a1);
}
}, [loading, error]);

return (
<div>
{artists && artists.length > 0 ? (
<div className="flex flex-col my-5 items-center">
<div className="flex-1 px-2 mx-2">
{/* <div className="text-lg font-bold">{constants.latest_monks}</div> */}
</div>
<div>
<GitaCarousel data={artists} />
</div>
</div>
) : (
<div></div>
)}
</div>
);
};

export default HomePage;

gita_carousel.jsx

    import React from "react";
import Carousel from "react-multi-carousel";
import "react-multi-carousel/lib/styles.css";
import { PlayIcon } from "../assets/icons/svg_icons";

const responsive = {
superLargeDesktop: {
// the naming can be any, depends on you.
breakpoint: { max: 4000, min: 3000 },
items: 5,
},
desktop: {
breakpoint: { max: 3000, min: 1024 },
items: 5,
},
tablet: {
breakpoint: { max: 1024, min: 464 },
items: 2,
},
mobile: {
breakpoint: { max: 464, min: 0 },
items: 1,
},
};

const GitaCarousel = (props) => {
const { data } = props;

return (
<div className="container mx-auto px-4 md:px-12">
<div className="flex flex-wrap -mx-1 lg:-mx-4">
<Carousel
swipeable={false}
draggable={false}
showDots={true}
responsive={responsive}
ssr={true}
infinite={true}
autoPlaySpeed={1000}
keyBoardControl={true}
customTransition="all .5"
transitionDuration={500}
containerClass="carousel-container"
removeArrowOnDeviceType={["tablet", "mobile"]}
deviceType="desktop"
>
{data.map((slide, index) => {
return (
<div
key={index}
className="group my-1 px-1 w-full cursor-pointer"
onClick={() => {
onClickHandler(slide.id);
}}
>
<article className="overflow-hidden rounded-lg shadow-lg">
<div className="relative cursor-pointer">
<img
alt="Placeholder"
className="block object-cover h-48 w-96"
src={slide.imageUrl}
/>
<button className="absolute top-1/2 right-1/2 -mr-3 -mt-3 rounded-lg opacity-0 group-hover:opacity-100">
<PlayIcon className="text-primary" />
</button>
</div>

<header className="items-center justify-between leading-tight p-2 md:p-4">
<h1 className="text-sm">{slide.title}</h1>
<h2 className="text-xs text-gray-400">{slide.subTitle}</h2>
</header>


</article>
</div>
);
})}
</Carousel>
</div>
</div>
);
};

export default GitaCarousel;

最佳答案

好的,我解决了这个问题。这是由于导出默认或导出典型问题而发生的,但我不知道插件是如何导出的。

下面是修复程序,它对我有用。

import Carousel from "react-multi-carousel";

const RMCarousel = Carousel.default? Carousel.default: Carousel;
<RMCarousel></RMCarousel>

关于reactjs - React 应用程序在生产环境中出现 "Element type is invalid"错误,但正在开发中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71000577/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com