0

I have this component

     import leftArrow from "../../../../../assets/svg/left.svg";

    export const LeftArrow = (props) => {
  const {className, style, onClick} = props
  return (
    <div
      className="slick-arrow"
      style={{...style, display: 'block'}}
      onClick={onClick}
    >
      <img src={leftArrow} alt="arrow_left"/>
    </div>
  );
}

I'm making custom arrows for the react-slick carousel, The problem is images are not being displayed. The path is right but the images are .svg icons. I'm also using babel. Any solutions, please?

It just displays undefined picture with alt "arrow left"

Nika Roffy
  • 891
  • 2
  • 8
  • 20

2 Answers2

1

You forgot to declare the leftArrow path and that is why it is not displaying you the image.

 export const LeftArrow = (props) => {
  const leftArrow = 'path_of_img'
  const {className, style, onClick} = props
  return (
    <div
      className={className}
      style={{...style, display: 'block'}}
      onClick={onClick}
    >
      <img src={leftArrow} alt="arrow_left"/>
    </div>
  );
}

Minor adjustments - You are getting className from props but are not using it.

Dharman
  • 30,962
  • 25
  • 85
  • 135
Utkarsh Goel
  • 175
  • 13
1

You are using the import wrong way. Try this

 export const LeftArrow = (props) => {
  const leftArrow = "../../../../../assets/svg/left.svg";
  const {className, style, onClick} = props;
  return (
    <div
      className={className}
      style={{...style, display: 'block'}}
      onClick={onClick}
    >
      <img src={leftArrow} alt="arrow_left"/>
    </div>
  );
}
Utkarsh Goel
  • 175
  • 13