Тёмный

Build a Stopwatch using React in 20 minutes! ⏱ 

Bro Code
Подписаться 1,9 млн
Просмотров 29 тыс.
50% 1

#reactjs #tutorial #course
This is a beginner's React project that uses only useState, useEffect, and useRef.
00:00:00 imports/exports
00:01:17 useState + useRef
00:02:48 function declarations
00:03:39 HTML
00:05:45 CSS
00:11:45 functions
00:14:06 useEffect()
00:16:10 formatTime()
00:19:19 conclusion

Опубликовано:

 

19 май 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 41   
@BroCodez
@BroCodez 4 месяца назад
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 4 месяца назад
hey Bro Code can you make a course about lua @BroCodez
@avanguly4843
@avanguly4843 4 месяца назад
i dont think he plays roblox lil bro@@RealRower1
@l213dhanesh3
@l213dhanesh3 3 месяца назад
Where are u code bro help me with angular js..... Missing u bro mava
@-_SleepAndEat_-
@-_SleepAndEat_- 28 дней назад
Bro can you do Kali Linux ?
@YoniYo12
@YoniYo12 Месяц назад
Best project tutorial ever! simple and to the point, thanks Bro
@Dylan12kpo1k2pDylan
@Dylan12kpo1k2pDylan 4 месяца назад
You beautiful man, keep adding to this playlist
@ejebeueh9113
@ejebeueh9113 4 месяца назад
So this bro gets 830 views while dancing toys get millions what a shame
@RadheKrishno-xr8ew
@RadheKrishno-xr8ew 4 месяца назад
Let the good things be with us 😁
@siddhantraj9425
@siddhantraj9425 20 дней назад
Thanks man. Helped a lot
@abdulbasit9364
@abdulbasit9364 Месяц назад
Bro you drop ur crown 👑❤
@rishabhkedia9304
@rishabhkedia9304 3 месяца назад
Please make Reactjs projects as well
@tofu7736
@tofu7736 4 месяца назад
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 3 месяца назад
Its over, it is only 4h. :D
@user-jr7lt8fk2b
@user-jr7lt8fk2b 2 месяца назад
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
@worldnothing3721
@worldnothing3721 4 месяца назад
bro are bringing backend development also
@Ashwini243
@Ashwini243 3 месяца назад
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?
@vibe-x8238
@vibe-x8238 Месяц назад
useRef is used to stop re-rendering your component when the variable(ref) is changed, which is not possible using useState().
@HabibHaris-fe7fy
@HabibHaris-fe7fy 3 месяца назад
please sir make a playlist on PANDAS, NUMPY please🌸 🌺🌼
@yogii1108
@yogii1108 Месяц назад
bro start next js using JavaScript waiting to learn from your channel
@java_learn6447
@java_learn6447 3 месяца назад
Sir please upload react form validations
@vibe-x8238
@vibe-x8238 Месяц назад
Hi Bro....Please make more videos.
@ranjithkumar7896
@ranjithkumar7896 3 месяца назад
Bro continue the react series, enjoying it try to upload next videos faster
@cobragaming-jv7iz
@cobragaming-jv7iz 13 дней назад
Baga cheppara bro
@1CDzy
@1CDzy 4 месяца назад
bro, please do C# on NET. development
@astartesidon609
@astartesidon609 23 часа назад
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?
@Delicatamente
@Delicatamente 28 дней назад
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?
@BishanTamang-rk5ji
@BishanTamang-rk5ji 4 месяца назад
Make java 2024 plz bro code love from Nepal 💓💓
@_amonimus_
@_amonimus_ 2 месяца назад
bro how many languages do you know
@ejebeueh9113
@ejebeueh9113 4 месяца назад
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 3 месяца назад
did u install live server?
@its-SK
@its-SK 4 месяца назад
hey bro code I am facing difficulties while learning js what should i do?
@1CDzy
@1CDzy 4 месяца назад
look at the documentation on JS, maybe it will help
@anandv1391
@anandv1391 19 дней назад
Mbuf
@RealRower1
@RealRower1 4 месяца назад
hey Bro Code can you make a course about lua
@RealRower1
@RealRower1 4 месяца назад
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
@ACCOUNT72197
@ACCOUNT72197 4 месяца назад
Hey i just wanted to say your last 5 videos don't appear in my sub feed. What is going on
@reynaldobuscagan7731
@reynaldobuscagan7731 19 дней назад
Hello, I'm a beginner I wonder what app you use, is it html or eclipse?
@yaroslavluchko8492
@yaroslavluchko8492 11 дней назад
this is VSCode
@jacklagos936
@jacklagos936 4 месяца назад
Bring parallax plz
@Beanbag59
@Beanbag59 3 месяца назад
Do u tutor
Далее
Build this React To-Do List app in 20 minutes! ☝
22:35
React useRef() hook introduction 🗳️
11:18
Просмотров 9 тыс.
ВЕЩЬ за ШАПКУ СУХАРЕЙ!
37:49
Просмотров 226 тыс.
The perfect plank !! 😱😱
00:19
Просмотров 2,8 млн
Super sport🤯
00:15
Просмотров 257 тыс.
Learn CSS in 1 hour 🎨
1:00:00
Просмотров 974 тыс.
ASMR Programming: Dark/Light Toggle | Pure CSS
5:33
Просмотров 13 тыс.
Build a JavaScript WEATHER APP in 30+ minutes! ☀️
38:40
Build this JS calculator in 15 minutes! 🖩
15:20
Просмотров 324 тыс.
Python snake game 🐍
33:06
Просмотров 547 тыс.
Python Object Oriented Programming in 10 minutes 🐍
10:04
ВЕЩЬ за ШАПКУ СУХАРЕЙ!
37:49
Просмотров 226 тыс.