尝试在网络包中使用'react-slick`时出现Uncaught (in promise) Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object.
错误。
const React = require("react");
const Slider = require("react-slick");
function MediaCarousel(props) {
const settings = {
dots: true,
infinite: true,
speed: 500,
slidesToShow: 1,
slidesToScroll: 1
};
return !props.stories ? null : <Slider>
<div><h3>1</h3></div>
<div><h3>2</h3></div>
<div><h3>3</h3></div>
<div><h3>4</h3></div>
<div><h3>5</h3></div>
<div><h3>6</h3></div>
</Slider>
}
exports.MediaCarousel = MediaCarousel;
答案 0 :(得分:0)
尝试使用
时已修复const Slider = require("react-slick").default;
我认为反应没有正确导出模块,或者我的加载器存在一些问题。
答案 1 :(得分:0)
尝试将设置传递给Slider组件:
<Slider {...settings} >
答案 2 :(得分:0)
Two things you will need to add in your code
1. <Slider {...settings}>
2. module.exports = SimpleSlider;
below code is working for me, please find if it could help you:
import React from 'react';
import {render} from 'react-dom';
import Slider from 'react-slick';
require('./carousel.scss');
class SimpleSlider extends React.Component {
render() {
var settings = {
dots: true,
autoplay: true,
arrows: true
};
return (
<Slider {...settings}>
<div><img src='../../src/assets/1.jpg' /></div>
<div><img src='../../src/assets/2.jpg' /></div>
<div><img src='../../src/assets/3.jpg' /></div>
<div><img src='../../src/assets/4.jpg' /></div>
</Slider>
);
}
}
module.exports = SimpleSlider;