Giter VIP home page Giter VIP logo

Comments (2)

IGhost-P avatar IGhost-P commented on August 16, 2024 1
import { useState, useEffect } from "react";
import min25 from "assets/images/25min.png";
import min20 from "assets/images/20min.png";
import min15 from "assets/images/15min.png";
import min10 from "assets/images/10min.png";
import min5 from "assets/images/5min.png";

/**
 * 5/10/15/20/25분 단위로 줄어드는 시간에 맞춰 이미지 변화시키는 함수
 * transition을 이용해서 자연스럽게 이미지가 바뀌게끔 하고 싶은데 어떻게 해야될지 모르겠어요.ㅠ
 * 아직 라우팅에 서툴러서 이 내용을 브라우저단에서 확인하고 싶은데 어떻게 해야할지 잘 모르겠네여..미생을 구해쥬세여 선배님들 ㅎㅎ ㅠ
 */

export function TimerImage() {
  const timeStamp = [min5, min10, min15, min20, min25];
  const [timerImage, setTimerImage] = useState(timeStamp[0]);
  const [count, setCount] = useState(0);
  const increment = () => setCount((prevCount) => prevCount + 1);

  useEffect(() => {
    console.log(count);
    const interval = setInterval(() => {
      if (count % 5 === 0) {
        setTimerImage(timeStamp[count / 5]);
      }
      increment();
    }, 1000);
    return () => clearInterval(interval);
  }, [count]);

  return (
    <div>
      <img src={timerImage} alt={"temp"} />
    </div>
  );
}

제가 생각한 방식은 이것 입니다!

from dailyreceipt-fe-web.

IGhost-P avatar IGhost-P commented on August 16, 2024

useInterval 방식으로 해결했습니다!
#14

from dailyreceipt-fe-web.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.