简体   繁体   English

如何在另一个 index.js 文件上导出 react-slick?

[英]How to export react-slick on another index.js file?

I want to add react-slick code on to my index.js (services folder) by following it's documentation, but it's not working.我想按照它的文档将 react-slick 代码添加到我的 index.js(服务文件夹)中,但它不起作用。

I'm using this method to show/call my pages on my main index.js我正在使用此方法在主 index.js 上显示/调用我的页面

index.js (Services Folder) , i want to add react slick code on this file index.js(服务文件夹) ,我想在这个文件上添加反应流畅的代码

const Services = () => {
    return (
        <ServicesContainer id="ourproducts">
        <ServicesH1>Our Products</ServicesH1>

    )
}
export default Services

index.js, this file is calling all index.js off my other pages index.js,这个文件调用了我其他页面的所有 index.js

import React, { useState } from 'react'
import Footer from '../components/Footer'
import HeroSection from '../components/HeroSection'
import InfoSection from '../components/InfoSection'
import { homeObjOne, homeObjTwo, homeObjThree } from '../components/InfoSection/Data'
import Navbar from '../components/Navbar'
import Services from '../components/Services'
import Sidebar from '../components/Sidebar'
const Home = () => {
    const [isOpen, setIsOpen] = useState(false);
    const toggle = () => {
        setIsOpen(!isOpen);
    };
    return (
        <>
            <Sidebar isOpen={isOpen} toggle={toggle} />
            <Navbar toggle={toggle}/>
            <HeroSection />
            <Services />
            <InfoSection {...homeObjOne}/>
            <InfoSection {...homeObjTwo}/>
            <InfoSection {...homeObjThree}/>
            <Footer />
        </>
    );
};
export default Home;

I tried this on index.js (Services Folder), but not working The error said "Only one default export allowed per module"我在 index.js(服务文件夹)上试过这个,但不起作用错误说“每个模块只允许一个默认导出”

import React, { Component } from "react";
import Slider from "react-slick";

import "~slick-carousel/slick/slick.css"; 
import "~slick-carousel/slick/slick-theme.css";

export default, Services class MultipleItems extends Component {
    render() {
      const settings = {
        dots: true,
        infinite: true,
        speed: 500,
        slidesToShow: 3,
        slidesToScroll: 3
      };
      return (
        <div>
          <h2> Multiple items </h2>
          <Slider {...settings}>
            <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>
            <div>
              <h3>7</h3>
            </div>
            <div>
              <h3>8</h3>
            </div>
            <div>
              <h3>9</h3>
            </div>
          </Slider>
        </div>
      );
    }
}

You're exporting two defaults in index.js file您正在 index.js 文件中导出两个默认值

Just remove the last line export default services只需删除最后一行export default services

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM