How to build a Stopwatch in React 🔥 | React JS Interview

Поделиться
HTML-код
  • Опубликовано: 31 дек 2024

Комментарии • 15

  • @akashingole
    @akashingole  Год назад +5

    If you like the video, don't forget to comment. Thank you for watching ❤

  • @A1996ARP2075
    @A1996ARP2075 Год назад

    Thanks please keep making more interview videos like these

  • @nitishkumarverma756
    @nitishkumarverma756 Год назад +1

    Shouldn't we use useRef for storing now as we are not going to rerender the UI for it ?

  • @SinghMusicpvtltd
    @SinghMusicpvtltd Год назад

    Awesome Sir

  • @engineerthings7486
    @engineerthings7486 Год назад

    Nicely explained 🙂

  • @SinghMusicpvtltd
    @SinghMusicpvtltd Год назад +1

    When u stopped the watch at 2 sec and if I want to let's continue from 2 sec then what to do sir?

    • @akashingole
      @akashingole  Год назад

      In that case do not setTime in handlestart(), just set the default value of Time as Date.now()

  • @sanyamjain4777
    @sanyamjain4777 Год назад

    Make more videos on these type of interview questions

  • @pratibhayadav4916
    @pratibhayadav4916 Год назад

    When i create stopwatch but with different condition so how to should i go i stuck at that point please guide me how i build my logic

    • @akashingole
      @akashingole  Год назад

      Hey you can text me at insta at codingjourneywithakash. Send me the ss of your code

  • @SinghMusicpvtltd
    @SinghMusicpvtltd Год назад

    Me learning React

  • @bhanusunka2840
    @bhanusunka2840 Год назад

    const handleStart = () => {
    setTime(Date.now());
    setNow(Date.now());
    clearInterval(intervalRef.current); // Edge case: clearing the previous Intervals,
    intervalRef.current = setInterval(() => {
    setTime(Date.now());
    }, 10);
    return () => clearInterval(intervalRef.current);
    };
    Like whenever we click restart button more than one time it doesn't stop when i click on the stop
    So to overcome this clearing timeInterval before creating a new one would result in more proper implementation