Search code examples
javascriptcssreactjsw3-css

Why is my slideshow not working in my React app?


I have imported w3.css in my React app and I'm trying to create a slideshow with 3 images in the same directory as the component being rendered. I'm new to React(also web development in general) and am struggling with styling my app. Code for Home.jsx

import React, { Component } from "react";
import "w3-css/w3.css";

export default class Home extends Component {
	render() {
		return (
			<div className="w3-container">
				<div className="w3-content w3-display-container">
					<img className="mySlides" src={"./1.jpg"} />
					<img className="mySlides" src={"./2.jpg"} />
					<img className="mySlides" src={"./3.jpg"} />
					<div
						className="w3-center w3-display-bottommiddle"
						style="width:100%"
					>
						<div className="w3-left" onclick="plusDivs(-1)">
							&#10094;
						</div>
						<div className="w3-right" onclick="plusDivs(1)">
							&#10095;
						</div>
						<span
							className="w3-badge demo w3-border"
							onclick="currentDiv(1)"
						/>
						<span
							className="w3-badge demo w3-border"
							onclick="currentDiv(2)"
						/>
						<span
							className="w3-badge demo w3-border"
							onclick="currentDiv(3)"
						/>
					</div>
				</div>
			</div>
		);
	}
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.6.3/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.6.3/umd/react-dom.production.min.js"></script>

I am not sure where I am going wrong. I followed the instructions here - https://www.w3schools.com/w3css/w3css_slideshow.asp and made a few changes as I thought were required in my app. I have attached the error I am getting on the local host page. The style prop expects a mapping from style properties to values, not a string. For example, style={{marginRight: spacing + 'em'}} when using JSX.


Solution

  • change

    <div
        className="w3-center w3-display-bottommiddle"
        style="width:100%"
    >
    

    to

    <div
        className="w3-center w3-display-bottommiddle"
        style={{width:"100%"}}
    >