custom paging slider missing config file for react.js

1.5k Views Asked by At

I am creating the custom paging slider from https://react-slick.neostack.com/docs/example/custom-paging/ I copied the code directly from the website and follow the instructions and installed the packages. When i try to run the code though i get the following error:

./src/Carousel.js Module not found: Can't resolve './config.js' in '/Users/mcoe/Documents/Code/my-app1/src'

Code:

import React, { Component } from 'react';
import ReactDOM from 'react-dom';
import Style from "react-responsive-carousel/lib/styles/carousel.min.css";
import { Carousel } from 'react-responsive-carousel';
import Slider from 'react-slick';
import { baseUrl } from "./config.js";

export default class SimpleSlider extends React.Component {
  render() {
    const settings = {
      customPaging: function(i) {
        return (
          <a>
            <img src={`${baseUrl}"Random1${i + 1}.png`} />
          </a>
        );
      },
      dots: true,
      dotsClass: "slick-dots slick-thumb",
      infinite: true,
      speed: 500,
      slidesToShow: 1,
      slidesToScroll: 1
    };
    return (
      <div>
        <h2>Custom Paging</h2>
        <Slider {...settings}>
          <div>
            <img src={baseUrl + "Random1.png"} />
          </div>
          <div>
            <img src={baseUrl + "Random1.png"} />
          </div>
          <div>
            <img src={baseUrl + "Random1.png"} />
          </div>
          <div>
            <img src={baseUrl + "Random1.png"} />
          </div>
        </Slider>
      </div>
    );
  }
}
2

There are 2 best solutions below

10
nbwoodward On

It looks like the component just wants a base url from a config file. The baseUrl needs to be the url path of your images. A relative path should work so if they are stored in my-app1/public/images/ you should be able to create a file config.js in the src directory like this:

//config.js
export const baseUrl = 'images/';
0
dwill09 On