Build a Stopwatch using React in 20 minutes! ⏱

  Рет қаралды 43,186

Bro Code

Bro Code

Күн бұрын

Пікірлер: 58
@BroCodez
@BroCodez Жыл бұрын
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 Жыл бұрын
hey Bro Code can you make a course about lua @BroCodez
@avanguly4843
@avanguly4843 Жыл бұрын
i dont think he plays roblox lil bro@@RealRower1
@l213dhanesh3
@l213dhanesh3 Жыл бұрын
Where are u code bro help me with angular js..... Missing u bro mava
@-_SleepAndEat_-
@-_SleepAndEat_- 9 ай бұрын
Bro can you do Kali Linux ?
@YoniYo12
@YoniYo12 9 ай бұрын
Best project tutorial ever! simple and to the point, thanks Bro
@syedmajid3202
@syedmajid3202 Ай бұрын
Thanks a lot, i completed your react course today, i learned alot from your tutorials, keep making new videos! 👍👍👍
@tofu7736
@tofu7736 Жыл бұрын
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 11 ай бұрын
Its over, it is only 4h. :D
@premkulkarni7578
@premkulkarni7578 15 күн бұрын
Thankyouuu , Finally wrapped up with react playlist (It took quite long for me to complete this but yeah totally worth watching it once again thankyouuu sooo muchhh...) feels bit confident about react after this
@Dylan12kpo1k2pDylan
@Dylan12kpo1k2pDylan Жыл бұрын
You beautiful man, keep adding to this playlist
@ejebeueh9113
@ejebeueh9113 Жыл бұрын
So this bro gets 830 views while dancing toys get millions what a shame
@RadheKrishno-xr8ew
@RadheKrishno-xr8ew Жыл бұрын
Let the good things be with us 😁
@fahimsium1013
@fahimsium1013 4 ай бұрын
Respect and love,brother. timer func is really crazy with setInterval
@samaali6589
@samaali6589 8 ай бұрын
Keep it up! Appreciate the efforts
@abdulbasit9364
@abdulbasit9364 9 ай бұрын
Bro you drop ur crown 👑❤
@syedmajid3202
@syedmajid3202 4 ай бұрын
Thanks a lot bro, keep making new videos, please make a tutorials on node.js and express.js!
@rishabhkedia9304
@rishabhkedia9304 Жыл бұрын
Please make Reactjs projects as well
@vanshgoyal-uo5cf
@vanshgoyal-uo5cf 5 ай бұрын
superb tutorial bro
@siddhantraj9425
@siddhantraj9425 9 ай бұрын
Thanks man. Helped a lot
@Ashwini243
@Ashwini243 11 ай бұрын
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 9 ай бұрын
useRef is used to stop re-rendering your component when the variable(ref) is changed, which is not possible using useState().
@gayantha6654
@gayantha6654 Ай бұрын
why elapsed time declared as a state variable? cannot use ref variable instead??
@astartesidon609
@astartesidon609 8 ай бұрын
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?
@ranjithkumar7896
@ranjithkumar7896 11 ай бұрын
Bro continue the react series, enjoying it try to upload next videos faster
@cobragaming-jv7iz
@cobragaming-jv7iz 8 ай бұрын
Baga cheppara bro
@Delicatamente
@Delicatamente 9 ай бұрын
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?
@IgorTr
@IgorTr Ай бұрын
every useState update causes a re-render. So in a case like this, where you have to re-render a lot, it would be best to try and make the part of your app that relies on that state as simple and tiny as possible, so you don't re-render more parts of your app than you have to.
@ideology8323
@ideology8323 5 ай бұрын
Thank you bro!
@hinatashoyo3891
@hinatashoyo3891 5 ай бұрын
BRO CAN WE GO AHEAD OF THIS NOW!!!! PLEAASEE
@HabibHaris-fe7fy
@HabibHaris-fe7fy 11 ай бұрын
please sir make a playlist on PANDAS, NUMPY please🌸 🌺🌼
@AbdalazezALBOGA
@AbdalazezALBOGA 10 ай бұрын
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
@worldnothing1928
@worldnothing1928 Жыл бұрын
bro are bringing backend development also
@OffsideFX_7
@OffsideFX_7 Жыл бұрын
hey bro code I am facing difficulties while learning js what should i do?
@1CDzy
@1CDzy Жыл бұрын
look at the documentation on JS, maybe it will help
@anandv1391
@anandv1391 8 ай бұрын
Mbuf
@Prateek_Mantry
@Prateek_Mantry 9 ай бұрын
Hi Bro....Please make more videos.
@yogii1108
@yogii1108 10 ай бұрын
bro start next js using JavaScript waiting to learn from your channel
@arkartm9989
@arkartm9989 8 ай бұрын
True Chad bro..❤
@abhishekagrawal1236
@abhishekagrawal1236 Ай бұрын
Is it full course?
@java_learn6447
@java_learn6447 11 ай бұрын
Sir please upload react form validations
@ejebeueh9113
@ejebeueh9113 Жыл бұрын
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 11 ай бұрын
did u install live server?
@something636-rr
@something636-rr Жыл бұрын
Hey i just wanted to say your last 5 videos don't appear in my sub feed. What is going on
@RealRower1
@RealRower1 Жыл бұрын
hey Bro Code can you make a course about lua
@RealRower1
@RealRower1 Жыл бұрын
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
@reynaldobuscagan7731
@reynaldobuscagan7731 8 ай бұрын
Hello, I'm a beginner I wonder what app you use, is it html or eclipse?
@yaroslavluchko8492
@yaroslavluchko8492 8 ай бұрын
this is VSCode
@BrunoTran-q6q
@BrunoTran-q6q 2 күн бұрын
this is the end :( Can we have more react tutorials please ? :(
@mohammedshehinthoombil1610
@mohammedshehinthoombil1610 6 ай бұрын
can you make redux tutorial
@1CDzy
@1CDzy Жыл бұрын
bro, please do C# on NET. development
@_amonimus_
@_amonimus_ 10 ай бұрын
bro how many languages do you know
@tasfin660
@tasfin660 8 ай бұрын
I want more react videos
@BishanTamang-rk5ji
@BishanTamang-rk5ji Жыл бұрын
Make java 2024 plz bro code love from Nepal 💓💓
@udoydas6513
@udoydas6513 5 ай бұрын
bro advance topics please
@Beanbag59
@Beanbag59 11 ай бұрын
Do u tutor
@jacklagos936
@jacklagos936 Жыл бұрын
Bring parallax plz
Build a DIGITAL CLOCK using React in 15 minutes! 🕒
16:00
Bro Code
Рет қаралды 21 М.
React useRef() hook introduction 🗳️
11:18
Bro Code
Рет қаралды 26 М.
Every React Concept Explained in 12 Minutes
11:53
Code Bootcamp
Рет қаралды 933 М.
Build this JS calculator in 15 minutes! 🖩
15:20
Bro Code
Рет қаралды 746 М.
React useContext() hook introduction 🧗‍♂️
11:37
Bro Code
Рет қаралды 45 М.
How to build a Stopwatch in React 🔥 | React JS Interview
10:15
The Sketchbook Series | Katsuya Terada
16:40
Trojan Horse Was a Unicorn
Рет қаралды 1,7 М.