react-slick - 元素类型无效:需要一个字符串
react-slick - Element type is invalid: expected a string
我正在尝试创建一个简单的滑块,但当我 map
数据而不是简单地将 html 添加到滑块时,我收到以下错误:
Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.
import React from 'react';
import Slider from 'react-slick';
import 'slick-carousel/slick/slick.css';
import 'slick-carousel/slick/slick-theme.css';
const WishAddImage = () => {
const imgArray = [
{
src: 'https://www.reiss.com/media/product/653/024/20-1.jpg?format=jpeg&auto=webp&quality=85&width=250&height=287&fit=bounds'
},
{
src: 'https://www.reiss.com/media/product/993/016/76-1.jpg?format=jpeg&auto=webp&quality=85&width=250&height=287&fit=bounds'
}
];
const sliderSettings = {
dots: true,
infinite: true,
speed: 500,
slidesToShow: 1,
slidesToScroll: 1
};
const wishImage = <Slider {...sliderSettings}>{imgArray.map(img => `<div><img src='${img.src}' /></div>`)}</Slider>;
// const wishImage = ( /* <-- this works as it should when html used */
// <Slider {...sliderSettings}>
// <div>
// <h1>1</h1>
// </div>
// <div>
// <h1>2</h1>
// </div>
// </Slider>
// );
return <div>{wishImage}</div>;
};
export default WishAddImage;
我看过这些类似的问题,但不适用于我:
- Uncaught Error: Element type is invalid: expected a string (for built-in components)
- Element type is invalid: expected a string (for built-in components) or a class/function
有什么明显的我遗漏的吗?
我正在使用 React & React-dom v 16.6.3
删除引号中的字符:
const wishImage = <Slider {...sliderSettings}>{imgArray.map(img => <div><img src={img.src} /></div>)}</Slider>;
我正在尝试创建一个简单的滑块,但当我 map
数据而不是简单地将 html 添加到滑块时,我收到以下错误:
Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.
import React from 'react';
import Slider from 'react-slick';
import 'slick-carousel/slick/slick.css';
import 'slick-carousel/slick/slick-theme.css';
const WishAddImage = () => {
const imgArray = [
{
src: 'https://www.reiss.com/media/product/653/024/20-1.jpg?format=jpeg&auto=webp&quality=85&width=250&height=287&fit=bounds'
},
{
src: 'https://www.reiss.com/media/product/993/016/76-1.jpg?format=jpeg&auto=webp&quality=85&width=250&height=287&fit=bounds'
}
];
const sliderSettings = {
dots: true,
infinite: true,
speed: 500,
slidesToShow: 1,
slidesToScroll: 1
};
const wishImage = <Slider {...sliderSettings}>{imgArray.map(img => `<div><img src='${img.src}' /></div>`)}</Slider>;
// const wishImage = ( /* <-- this works as it should when html used */
// <Slider {...sliderSettings}>
// <div>
// <h1>1</h1>
// </div>
// <div>
// <h1>2</h1>
// </div>
// </Slider>
// );
return <div>{wishImage}</div>;
};
export default WishAddImage;
我看过这些类似的问题,但不适用于我:
- Uncaught Error: Element type is invalid: expected a string (for built-in components)
- Element type is invalid: expected a string (for built-in components) or a class/function
有什么明显的我遗漏的吗?
我正在使用 React & React-dom v 16.6.3
删除引号中的字符:
const wishImage = <Slider {...sliderSettings}>{imgArray.map(img => <div><img src={img.src} /></div>)}</Slider>;