DEV Community

Maxim Nosov ✪
Maxim Nosov ✪

Posted on

5

Hacktoberfest - PR#3

Hi!

I hope you are enjoying Hacktoberfest with lots of different projects.

Project

This week I contributed to React JS project. In this project you can create a meeting via Calendly and join other meetings as well.

Issue

For my Issue, I had to add dynamic background image to the app, so that background image is changing every 10 seconds.

Solution

For my PR I added a function that would change the background image:

const [counter, setCounter] = useState(0);
  const [backgroundClass, setBackgroundClass] = useState("");
  const backgroundImages = [
    "backgroundImage1",
    "backgroundImage2",
    "backgroundImage3",
    "backgroundImage4",
    "backgroundImage5",
  ];

function changeBackgroundImage() {
    if (counter === 4) {
      setCounter(0);
    } else {
      setBackgroundClass(backgroundImages[counter]);
      setCounter(counter + 1);
    }
  }

  useEffect(() => {
    setTimeout(() => {
      changeBackgroundImage();
    }, 10000);
  }, [counter]);
Enter fullscreen mode Exit fullscreen mode

Summary

It took some time for me to find the way to implement that feature, but it was a great experience!

Sentry blog image

How I fixed 20 seconds of lag for every user in just 20 minutes.

Our AI agent was running 10-20 seconds slower than it should, impacting both our own developers and our early adopters. See how I used Sentry Profiling to fix it in record time.

Read more

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay