Build a Stopwatch using React in 20 minutes! ⏱

  Рет қаралды 44,212

Bro Code

Bro Code

Күн бұрын

Пікірлер: 61
@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 10 ай бұрын
Best project tutorial ever! simple and to the point, thanks Bro
@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 Жыл бұрын
Its over, it is only 4h. :D
@syedmajid3202
@syedmajid3202 2 ай бұрын
Thanks a lot, i completed your react course today, i learned alot from your tutorials, keep making new videos! 👍👍👍
@premkulkarni7578
@premkulkarni7578 Ай бұрын
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
@حذيفةأحمد
@حذيفةأحمد 9 күн бұрын
i start switching the milliseconds to the logical time from the smaller unit to the bigger one, so it can be easy to read and understand : function formatTime() { let millieSeconds = Math.floor((elapsedtime / 10) % 100); let seconds = Math.floor(elapsedtime / 1000); let minutes = Math.floor(seconds / 60); let hours = Math.floor(minutes / 60); return `${hours}:${minutes}:${seconds}:${millieSeconds}`; } it give the same result.
@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 5 ай бұрын
Respect and love,brother. timer func is really crazy with setInterval
@abdulbasit9364
@abdulbasit9364 10 ай бұрын
Bro you drop ur crown 👑❤
@samaali6589
@samaali6589 9 ай бұрын
Keep it up! Appreciate the efforts
@syedmajid3202
@syedmajid3202 4 ай бұрын
Thanks a lot bro, keep making new videos, please make a tutorials on node.js and express.js!
@siddhantraj9425
@siddhantraj9425 9 ай бұрын
Thanks man. Helped a lot
@vanshgoyal-uo5cf
@vanshgoyal-uo5cf 6 ай бұрын
superb tutorial bro
@hinatashoyo3891
@hinatashoyo3891 5 ай бұрын
BRO CAN WE GO AHEAD OF THIS NOW!!!! PLEAASEE
@ranjithkumar7896
@ranjithkumar7896 Жыл бұрын
Bro continue the react series, enjoying it try to upload next videos faster
@cobragaming-jv7iz
@cobragaming-jv7iz 9 ай бұрын
Baga cheppara bro
@rishabhkedia9304
@rishabhkedia9304 Жыл бұрын
Please make Reactjs projects as well
@yogii1108
@yogii1108 10 ай бұрын
bro start next js using JavaScript waiting to learn from your channel
@Ashwini243
@Ashwini243 Жыл бұрын
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 10 ай бұрын
useRef is used to stop re-rendering your component when the variable(ref) is changed, which is not possible using useState().
@ideology8323
@ideology8323 6 ай бұрын
Thank you bro!
@Prateek_Mantry
@Prateek_Mantry 10 ай бұрын
Hi Bro....Please make more videos.
@حذيفةأحمد
@حذيفةأحمد 9 күн бұрын
شكرا صديقي
@AbdalazezALBOGA
@AbdalazezALBOGA 11 ай бұрын
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
@arkartm9989
@arkartm9989 9 ай бұрын
True Chad bro..❤
@HabibHaris-fe7fy
@HabibHaris-fe7fy Жыл бұрын
please sir make a playlist on PANDAS, NUMPY please🌸 🌺🌼
@BrunoTran-q6q
@BrunoTran-q6q 19 күн бұрын
this is the end :( Can we have more react tutorials please ? :(
@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?
@tasfin660
@tasfin660 8 ай бұрын
I want more react videos
@java_learn6447
@java_learn6447 Жыл бұрын
Sir please upload react form validations
@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.
@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
@mohammedshehinthoombil1610
@mohammedshehinthoombil1610 6 ай бұрын
can you make redux tutorial
@BishanTamang-rk5ji
@BishanTamang-rk5ji Жыл бұрын
Make java 2024 plz bro code love from Nepal 💓💓
@gayantha6654
@gayantha6654 2 ай бұрын
why elapsed time declared as a state variable? cannot use ref variable instead??
@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 9 ай бұрын
Mbuf
@abhishekagrawal1236
@abhishekagrawal1236 Ай бұрын
Is it full course?
@1CDzy
@1CDzy Жыл бұрын
bro, please do C# on NET. development
@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 Жыл бұрын
did u install live server?
@reynaldobuscagan7731
@reynaldobuscagan7731 9 ай бұрын
Hello, I'm a beginner I wonder what app you use, is it html or eclipse?
@yaroslavluchko8492
@yaroslavluchko8492 9 ай бұрын
this is VSCode
@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
@_amonimus_
@_amonimus_ 11 ай бұрын
bro how many languages do you know
@udoydas6513
@udoydas6513 6 ай бұрын
bro advance topics please
@l4n1skyy
@l4n1skyy 15 күн бұрын
i love you
@jacklagos936
@jacklagos936 Жыл бұрын
Bring parallax plz
@Beanbag59
@Beanbag59 Жыл бұрын
Do u tutor
Build a DIGITAL CLOCK using React in 15 minutes! 🕒
16:00
Bro Code
Рет қаралды 21 М.
React useEffect() hook introduction 🌟
19:52
Bro Code
Рет қаралды 39 М.
Banana vs Sword on a Conveyor Belt
01:00
Mini Katana
Рет қаралды 77 МЛН
And what’s your height? 😁 @karina-kola
00:10
Andrey Grechka
Рет қаралды 52 МЛН
Build this JS STOPWATCH in 18 minutes! ⏱
18:06
Bro Code
Рет қаралды 36 М.
This is the Only Right Way to Write React clean-code - SOLID
18:23
Build a Simple Age Calculator Part 2
55:08
Kayode Samson Adelola
Рет қаралды 2
Build this React To-Do List app in 20 minutes! ☝
22:35
Bro Code
Рет қаралды 86 М.
React useContext() hook introduction 🧗‍♂️
11:37
Bro Code
Рет қаралды 47 М.
I Spent 100 Hours Inside The Pyramids!
21:43
MrBeast
Рет қаралды 76 МЛН
Build this JS calculator in 15 minutes! 🖩
15:20
Bro Code
Рет қаралды 783 М.
Insane Theoretical Physics Discussion with ChatGPT and DeepSeek
4:59
Unzicker's Real Physics
Рет қаралды 33 М.
All useEffect Mistakes Every Junior React Developer Makes
22:23
How to build a Stopwatch in React 🔥 | React JS Interview
10:15