Build a Stopwatch using React in 20 minutes! ⏱

  Рет қаралды 37,444

Bro Code

Bro Code

Күн бұрын

Пікірлер: 51
@BroCodez
@BroCodez 8 ай бұрын
import Stopwatch from './Stopwatch.jsx'; function App() { return (); } export default App; import React, {useState, useEffect, useRef} from 'react'; function Stopwatch(){ const [isRunning, setIsRunning] = useState(false); const [elapsedTime, setElapsedTime] = useState(0); const intervalIdRef = useRef(null); const startTimeRef = useRef(0); useEffect(() => { if(isRunning){ intervalIdRef.current = setInterval(() => { setElapsedTime(Date.now() - startTimeRef.current); }, 10); } return () => { clearInterval(intervalIdRef.current); } }, [isRunning]); function start(){ setIsRunning(true); startTimeRef.current = Date.now() - elapsedTime; } function stop(){ setIsRunning(false); } function reset(){ setElapsedTime(0); setIsRunning(false); } function formatTime(){ let hours = Math.floor(elapsedTime / (1000 * 60 * 60)); let minutes = Math.floor(elapsedTime / (1000 * 60) % 60); let seconds = Math.floor(elapsedTime / (1000) % 60); let milliseconds = Math.floor((elapsedTime % 1000) / 10); hours = String(hours).padStart(2, "0"); minutes = String(minutes).padStart(2, "0"); seconds = String(seconds).padStart(2, "0"); milliseconds = String(milliseconds).padStart(2, "0"); return `${minutes}:${seconds}:${milliseconds}`; } return( {formatTime()} Start Stop Reset ); } export default Stopwatch body{ display: flex; flex-direction: column; align-items: center; background-color: hsl(0, 0%, 95%); } .stopwatch{ display: flex; flex-direction: column; align-items: center; border: 5px solid; border-radius: 50px; background-color: white; padding: 30px; } .display{ font-size: 5rem; font-family: monospace; font-weight: bold; color: hsl(0, 0%, 30%); text-shadow: 2px 2px 2px hsla(0, 0%, 0%, 0.75); margin-bottom: 25px; } .controls button{ font-size: 1.5rem; font-weight: bold; padding: 10px 20px; margin: 5px; min-width: 125px; border: none; border-radius: 10px; cursor: pointer; color: white; transition: background-color 0.5s ease; } .start-button{ background-color: hsl(115, 100%, 40%); } .start-button:hover{ background-color: hsl(115, 100%, 35%); } .stop-button{ background-color: hsl(10, 90%, 50%); } .stop-button:hover{ background-color: hsl(10, 90%, 45%); } .reset-button{ background-color: hsl(205, 90%, 60%); } .reset-button:hover{ background-color: hsl(205, 90%, 55%); }
@RealRower1
@RealRower1 8 ай бұрын
hey Bro Code can you make a course about lua @BroCodez
@avanguly4843
@avanguly4843 8 ай бұрын
i dont think he plays roblox lil bro@@RealRower1
@l213dhanesh3
@l213dhanesh3 8 ай бұрын
Where are u code bro help me with angular js..... Missing u bro mava
@-_SleepAndEat_-
@-_SleepAndEat_- 5 ай бұрын
Bro can you do Kali Linux ?
@YoniYo12
@YoniYo12 6 ай бұрын
Best project tutorial ever! simple and to the point, thanks Bro
@tofu7736
@tofu7736 8 ай бұрын
Just waiting for 12:00:00 hours React video to come By the way I have watched all the web development courses you’ve been uploading. Thanks bro because of you i can understand and learn web dev. Big heart for BRO ARMY 💜💜💜💜💜
@nesa6582
@nesa6582 8 ай бұрын
Its over, it is only 4h. :D
@fahimsium1013
@fahimsium1013 22 күн бұрын
Respect and love,brother. timer func is really crazy with setInterval
@ejebeueh9113
@ejebeueh9113 8 ай бұрын
So this bro gets 830 views while dancing toys get millions what a shame
@RadheKrishno-xr8ew
@RadheKrishno-xr8ew 8 ай бұрын
Let the good things be with us 😁
@Dylan12kpo1k2pDylan
@Dylan12kpo1k2pDylan 8 ай бұрын
You beautiful man, keep adding to this playlist
@syedmajid3202
@syedmajid3202 9 күн бұрын
Thanks a lot bro, keep making new videos, please make a tutorials on node.js and express.js!
@Ashwini243
@Ashwini243 7 ай бұрын
Hi, I am based in the USA.I really love your videos and they are interview oriented. Can you explain why you used useRef variable?
@Prateek_Mantry
@Prateek_Mantry 6 ай бұрын
useRef is used to stop re-rendering your component when the variable(ref) is changed, which is not possible using useState().
@rishabhkedia9304
@rishabhkedia9304 8 ай бұрын
Please make Reactjs projects as well
@samaali6589
@samaali6589 4 ай бұрын
Keep it up! Appreciate the efforts
@abdulbasit9364
@abdulbasit9364 5 ай бұрын
Bro you drop ur crown 👑❤
@siddhantraj9425
@siddhantraj9425 5 ай бұрын
Thanks man. Helped a lot
@vanshgoyal-uo5cf
@vanshgoyal-uo5cf 2 ай бұрын
superb tutorial bro
@hinatashoyo3891
@hinatashoyo3891 Ай бұрын
BRO CAN WE GO AHEAD OF THIS NOW!!!! PLEAASEE
@HabibHaris-fe7fy
@HabibHaris-fe7fy 7 ай бұрын
please sir make a playlist on PANDAS, NUMPY please🌸 🌺🌼
@AbdalazezALBOGA
@AbdalazezALBOGA 6 ай бұрын
hey bro can u make a course about laravel for beginners u r so good and now i only can learn anything from you thanks a lot
@ideology8323
@ideology8323 2 ай бұрын
Thank you bro!
@ranjithkumar7896
@ranjithkumar7896 7 ай бұрын
Bro continue the react series, enjoying it try to upload next videos faster
@cobragaming-jv7iz
@cobragaming-jv7iz 5 ай бұрын
Baga cheppara bro
@yogii1108
@yogii1108 6 ай бұрын
bro start next js using JavaScript waiting to learn from your channel
@worldnothing1928
@worldnothing1928 8 ай бұрын
bro are bringing backend development also
@Delicatamente
@Delicatamente 5 ай бұрын
So, technicaly, timer re-renders every 10 miliseconds, just because of changing useState variable "elapsedTime" in Stopwatch component, what provide full re-render of Stopwatch component? Or re-render happens as a result of changing that useState variable "elapsedTime", which is mentioned in function "formatTime", which (this function) is mapped to timer component? And because of this bound React re-renders component? Can someone explain me this technical details?
@Prateek_Mantry
@Prateek_Mantry 6 ай бұрын
Hi Bro....Please make more videos.
@java_learn6447
@java_learn6447 8 ай бұрын
Sir please upload react form validations
@arkartm9989
@arkartm9989 4 ай бұрын
True Chad bro..❤
@astartesidon609
@astartesidon609 4 ай бұрын
so we can conclude that even if we stop the countdown for a couple of minutes still the time in between when we restart still gonna carry over because we based our elapsed time only on a date?
@mohammedshehinthoombil1610
@mohammedshehinthoombil1610 2 ай бұрын
can you make redux tutorial
@RealRower1
@RealRower1 8 ай бұрын
hey Bro Code can you make a course about lua
@RealRower1
@RealRower1 8 ай бұрын
ye but atleast he has something to post about and i think he is gonna get alot of views because lot of people want to learn lua for game dev in roblox and there is not a good course to learning it so he will be the first
@udoydas6513
@udoydas6513 2 ай бұрын
bro advance topics please
@BishanTamang-rk5ji
@BishanTamang-rk5ji 8 ай бұрын
Make java 2024 plz bro code love from Nepal 💓💓
@tasfin660
@tasfin660 4 ай бұрын
I want more react videos
@1CDzy
@1CDzy 8 ай бұрын
bro, please do C# on NET. development
@its-SK
@its-SK 8 ай бұрын
hey bro code I am facing difficulties while learning js what should i do?
@1CDzy
@1CDzy 8 ай бұрын
look at the documentation on JS, maybe it will help
@anandv1391
@anandv1391 5 ай бұрын
Mbuf
@ejebeueh9113
@ejebeueh9113 8 ай бұрын
Bro please i need help I just started learning jave script and I'm watching your full course so when I linked my css ,js and HTML and tried the same code that you wrote and opened it with live server nothing appeared on the web and its console it says error404 Sorry for my poor words I hope that you understand what I mean, thanks
@aman1589
@aman1589 8 ай бұрын
did u install live server?
@something636-rr
@something636-rr 8 ай бұрын
Hey i just wanted to say your last 5 videos don't appear in my sub feed. What is going on
@reynaldobuscagan7731
@reynaldobuscagan7731 5 ай бұрын
Hello, I'm a beginner I wonder what app you use, is it html or eclipse?
@yaroslavluchko8492
@yaroslavluchko8492 4 ай бұрын
this is VSCode
@_amonimus_
@_amonimus_ 6 ай бұрын
bro how many languages do you know
@jacklagos936
@jacklagos936 8 ай бұрын
Bring parallax plz
@Beanbag59
@Beanbag59 7 ай бұрын
Do u tutor
React useEffect() hook introduction 🌟
19:52
Bro Code
Рет қаралды 27 М.
Build this React To-Do List app in 20 minutes! ☝
22:35
Bro Code
Рет қаралды 57 М.
Когда отец одевает ребёнка @JaySharon
00:16
История одного вокалиста
Рет қаралды 1,6 МЛН
Don't look down on anyone#devil  #lilith  #funny  #shorts
00:12
Devil Lilith
Рет қаралды 3,2 МЛН
Worst flight ever
00:55
Adam W
Рет қаралды 30 МЛН
SHAPALAQ 6 серия / 3 часть #aminkavitaminka #aminak #aminokka #расулшоу
00:59
Аминка Витаминка
Рет қаралды 2,2 МЛН
Learn HTML in 1 hour 🌎
1:00:00
Bro Code
Рет қаралды 2,1 МЛН
Build a DIGITAL CLOCK using React in 15 minutes! 🕒
16:00
Bro Code
Рет қаралды 17 М.
How to build a Stopwatch in React 🔥 | React JS Interview
10:15
Akash Ingole
Рет қаралды 4,9 М.
React useRef() hook introduction 🗳️
11:18
Bro Code
Рет қаралды 19 М.
Learn CSS in 1 hour 🎨
1:00:00
Bro Code
Рет қаралды 1,2 МЛН
10 Crazy Python Operators That I Rarely Use
11:37
Indently
Рет қаралды 22 М.
The Easiest Way to Build Websites
10:56
Sajid
Рет қаралды 509 М.
You might not need useEffect() ...
21:45
Academind
Рет қаралды 162 М.
Build this JS calculator in 15 minutes! 🖩
15:20
Bro Code
Рет қаралды 580 М.
Когда отец одевает ребёнка @JaySharon
00:16
История одного вокалиста
Рет қаралды 1,6 МЛН