Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

197
Views
React slider styling not applying

I am using dummy data and some slider logic I referenced from a video for a slider component that simply switches between just two images for now.

Here is the codesandbox link if it makes things easier.

import { useState } from "react";
import { Flex, Box, Text, Image } from "@chakra-ui/react";
import styles from "./works.module.scss";

const Works = () => {
  const [currentSlide, setCurrentSlide] = useState(0);

  const data = [
    {
      id: "0",
      text: "In Progress..",
      img: "https://www.marketplace.org/wp-content/uploads/2019/08/Fake-twitter.jpg?w=1200",
    },

    {
      id: "1",
      text: "Coming Soon..",
      img: "https://www.desktopbackground.org/download/1920x1080/2011/05/16/204237_grey-gaussian-blur-wallpaper-jpg_1920x1200_h.jpg",
    },
  ];

  const length = data.length;

  const nextSlide = (length) => {
    setCurrentSlide(currentSlide === length - 1 ? 0 : currentSlide + 1);
  };

  const prevSlide = () => {
    setCurrentSlide(currentSlide === 0 ? length - 1 : currentSlide - 1);
  };

  
  return (
    <Flex justify="center" m="50px">
      <Image
        src="assets/arrow2.png"
        w="50px"
        h="50px"
        alt=""
        onClick={() => prevSlide(length)}
        className={styles.left}
      />
      <Box borderRadius="20px" w="500px" h="500px" bg="black">
        {data.map((d, index) => (
          <Flex
            className={
              index === currentSlide ? styles["slide active"] : styles.slide
            }
            m="20px"
            h="80%"
          >
            {index === currentSlide && (
              <Image className={styles.img} src={d.img} alt={d.text} w="100%" h="100%" />
            )}
          </Flex>
        ))}
      </Box>
      <Image
        src="assets/arrow2.png"
        alt=""
        w="50px"
        h="50px"
        onClick={() => nextSlide(length)}
        className={styles.right}
      />
    </Flex>
  );
};
export default Works;

However, it seems to me that the slides.active styling is not applying for some reason. Does anyone have any insight as to why this is not working correctly? Thanks!!

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!