커뮤니티
포인트
쿠폰
내 강의실
국비 신청 내역
증명서
계정
로그아웃
학습 질문
개발 일지
나의 활동
답변 완료
코드가 작동 되지 않습니다 ㅠ
undefined주차
북마크
조*수
댓글
3
추천
0
조회수
22
조회수
22
답변 완료

import './style.css';

import { useRef, useState, useEffect } from 'react';


function App() {

    const [time, setTime] = useState(null);

    const timerRef = useRef(null);


    useEffect(() => {

      setTime(new Date());

      timerRef.current=setInterval(() => {

        setTime(new Date());

      }, 1000);

    }, []);


    function handleStop() {

    clearInterval(timerRef.current);

    timerRef.current = null;

  }


    function handleStart() {

    if (timerRef.current === null) {

      timerRef.current = setInterval(() => {

        setTime(new Date());

      }, 1000);

    }

  }


    if (time === null) return null;


    return (

        <section className="app">

            <div className="watch_container">

                <h1>⏰ 현재시간 ⏰</h1>

                <p>{time.toLocaleTimeString()}</p>


                <div className="action_button_container">

                    <button

                        className="start_button_container"

                        onClick={handleStart}

                    >

                        시작

                    </button>

                    <button

                        className="stop_button_container"

                        onClick={handleStop}

                    >

                        멈춤

                    </button>

                </div>

            </div>

        </section>

    );

}


export default App;



이 코드대로 미니타이머 작업을 했는데, 멈춤을 눌러도 멈춰지지가 않네요 ㅠㅠ

어디가 잘 못 된 것인지 확인 부탁드립니다.


그리고 저번에 교재 PDF 관련에 대해 질문했는데, 아직 확인이 안 된 것인지 알려주세요 ...



취소
 공유
취소
댓글 0
댓글 알림
나의얼굴