Dark Theme Toggle - React JS - Switch From Light Theme To Dark Theme - Beginner Tutorial

  Рет қаралды 31,436

Code Commerce

Code Commerce

Күн бұрын

Пікірлер: 61
@TrianeP
@TrianeP 2 жыл бұрын
I enjoy how excited you are when speaking about this. Great video
@codecommerce
@codecommerce 2 жыл бұрын
Thank you!
@daze_music
@daze_music 2 жыл бұрын
Damn my dude, that's like insanely easier then most of how people use the theme toggler trend. That was very informative and accurate. Thanks so much.
@codecommerce
@codecommerce 2 жыл бұрын
Thanks dude - glad you liked it!
@abedalraoufzeidan1461
@abedalraoufzeidan1461 11 ай бұрын
your tutorials are awosome
@codecommerce
@codecommerce 10 ай бұрын
thank you sir!
@kurwacherry
@kurwacherry Жыл бұрын
thanks man, this was just what i needed
@onahsunday0612
@onahsunday0612 2 жыл бұрын
I have seen several videos but this is Exactly what I am looking for thanks dude.
@codecommerce
@codecommerce 2 жыл бұрын
Onah, thank you dude!
@coreynoble8532
@coreynoble8532 2 жыл бұрын
Thank you, spent way too much time trying to figure this out using other resources. This was simple and makes a tonne of sense. One suggestion. Either already have the markup in-place, or have bookmarks pointing to the actual implementation of the theme variables / context switch
@codecommerce
@codecommerce 2 жыл бұрын
Thank you Corey
@StachaC
@StachaC 2 жыл бұрын
Thank you for the amazing tutorial! You just forgot to change the "Light Theme" heading and the toggle. This code worked for me: {theme === "light" ? Light Theme : Dark Theme} {theme === "light" ? ( ) : ( )}
@codecommerce
@codecommerce 2 жыл бұрын
Thank you shakeel
@showcaserv4209
@showcaserv4209 2 жыл бұрын
This is exactly what I’m looking for 🤯
@GauravSingh-bc1ug
@GauravSingh-bc1ug Жыл бұрын
best method ever seen
@sifact1391
@sifact1391 Жыл бұрын
So simple and elegant
@codecommerce
@codecommerce Жыл бұрын
Thanks!
@ahmed-alamodi
@ahmed-alamodi 2 жыл бұрын
I like your way, simple and easy 👏
@vignesh-xb5uz
@vignesh-xb5uz Жыл бұрын
Nice work.....pls continue do this work 🇮🇳❣️
@codecommerce
@codecommerce Жыл бұрын
Thanks!
@amacodes7347
@amacodes7347 2 жыл бұрын
Great content really loved it and the explanation was absolutely awesone. I was thinking of instead making the dark theme as a component to be used on other pages
@codecommerce
@codecommerce 2 жыл бұрын
That's a great idea!
@sarafkaushik4745
@sarafkaushik4745 Жыл бұрын
thank you nice explanation
@angshumanpathak2300
@angshumanpathak2300 Жыл бұрын
Hey can you explain me one thing how did the small icons changed into white onclick of the dark mode
@samcuber4364
@samcuber4364 2 жыл бұрын
Thank you soo much for this!!
@codecommerce
@codecommerce 2 жыл бұрын
You're so welcome!
@chadthunder6973
@chadthunder6973 2 жыл бұрын
How can this toggle be applied from another component? Say a navbar component instead of in the App where data-theme is defined.
@mohammedhassan8942
@mohammedhassan8942 2 жыл бұрын
bro if you keep up with type of unique content you surely gain more subs
@codecommerce
@codecommerce 2 жыл бұрын
Thanks my dude!
@ahtidotpk
@ahtidotpk 2 жыл бұрын
That's realy amazing thank you so much
@codecommerce
@codecommerce 2 жыл бұрын
I'm glad you like it man!
@g_69westside51
@g_69westside51 Жыл бұрын
on 25:56 can someone explain to me whats the meaning of the conditional statements on line 8 and 11 .Thankyou
@userabc200
@userabc200 Жыл бұрын
how to add this is in an ongoing project?
@HaNaxHeart
@HaNaxHeart 2 жыл бұрын
thank you so much !!
@gajananmehta7215
@gajananmehta7215 2 жыл бұрын
amazing👍
@romimaximus
@romimaximus 2 жыл бұрын
Hey i have a question ?, at 12:00, whats that "[data-theme='dark']{ }" came from ?.. and at 25:00, 'dark' and 'light', where's the 'light' theme ? , cause i see the 'dark theme' you that you created in the css earlier, but i dont see the 'light' theme ? ...im lost here, kkkkk, by the way awesome video tutorial !! , and thank you for sharing 😎👍
@akamaru1822
@akamaru1822 2 жыл бұрын
`data-theme` is an HTML attribute he assigns at @26:00. He sets the value of the `data-theme` attribute to be equal to that of the `theme` hook. The `theme` hook on initiation ( `App.js` Line 8) is checking if there's a local session with the name `theme`, if not found then assign the value of the `theme` hook` to equal 'light'. From there the theme-toggle button is flipping through these and setting the value of the theme variable to `light` or `dark`, this value is saved to the local storage so that the next time you visit the page there'll be a value for that 'theme' local storage. One thing that is confusing is the way the useLocalStorage hook is instantiated. You can check the usage by looking for `use-local-storage` npm package. It should be instantiated like so, useLocalStorage("name", "value"); In our case, name=theme, value=light
@romimaximus
@romimaximus 2 жыл бұрын
@@akamaru1822 awsome, thankx for the reply, im more confused about the 'light' theme, cause i dont see any css rules setup for this 'light' theme, anyway thankx, you cleared out most of my doubts 👍
@akamaru1822
@akamaru1822 2 жыл бұрын
​@@romimaximus np. The 'light' theme is nothing more the variables set in the `:root` at 12:35. basically we are adding the 'data-theme='dark'' attribute to then override the variables set in the ':root' with that in `[data-theme='dark']`. On the first page visit, we set `useLocalStorage("theme", "light")` // as there is no local storage with the key 'theme; The css variables in ':root' are instantiated, this is our `light` theme. When we toggle the theme, light to dark: Setting `theme` to "dark" (on first toggle) This causes a page re-render as we set `data-theme={theme}` , data-theme attribute determines which css theme to use. Now, since `[data-theme='dark']` we override the CSS variables we declared in `:root` with those in `[data-theme='dark']` If you look at the index.css file, you can see that ':root' and `[dark-theme='dark']` are an inverse of each other, hence light and dark themes
@romimaximus
@romimaximus 2 жыл бұрын
@@akamaru1822 well thank you very much for your help and reply...i really apreciate 😎👍
@codecommerce
@codecommerce 2 жыл бұрын
Thank you for the clarification John
@anishbishnoi29xD
@anishbishnoi29xD 2 жыл бұрын
u r awesome ♥️ Keep it up . MERN STACK Will be great. ♥️
@azimb2280
@azimb2280 2 жыл бұрын
how do i implementation theme in other page in one button
@codecommerce
@codecommerce 2 жыл бұрын
Azim - I'm actually doing another dark theme toggle using context
@czarscrib3680
@czarscrib3680 2 жыл бұрын
Bro what's your internet speed 😩 plus how did that install so quickly
@codecommerce
@codecommerce 2 жыл бұрын
Sup dude! We have 1gig up/down here :)
@czarscrib3680
@czarscrib3680 2 жыл бұрын
@@codecommerce 😯
@illusry7631
@illusry7631 2 жыл бұрын
24:10 the javascript
@mahammadmansurali1099
@mahammadmansurali1099 2 жыл бұрын
Make a video on react-redux with using api...please
@codecommerce
@codecommerce 2 жыл бұрын
Thats a great idea!
@kenansari
@kenansari 2 жыл бұрын
thank you
@codecommerce
@codecommerce 2 жыл бұрын
You're welcome
@xidnebwoz
@xidnebwoz 2 жыл бұрын
How about react authentication?
@showcaserv4209
@showcaserv4209 2 жыл бұрын
That’s a good idea! Really wish i could afford a database.
@codecommerce
@codecommerce 2 жыл бұрын
Absolutely - a MERN video sounds fun.
@showcaserv4209
@showcaserv4209 2 жыл бұрын
I noticed that the circle is not moving, how do I make it move onclick?
@codecommerce
@codecommerce 2 жыл бұрын
Hi! Yes- that is just a static icon so there will be no change. Two options here: Option 1 - (and in my opinion the easiest way) would be to add the identical react-icon that is reversed. Then add a function to toggle between the two icons. Much like how we do for the hamburger menu. Option 2 - We could code a custom button in CSS.
@showcaserv4209
@showcaserv4209 2 жыл бұрын
@@codecommerce thanks
@miirshe
@miirshe Жыл бұрын
Thanks less code more efficient and so easy I` excited to be teach me (UseLocaalStorage)
@aymenbachiri-yh2hd
@aymenbachiri-yh2hd Жыл бұрын
thank you
Build A React JS Website From Scratch - CSS Grid Layout in React
1:28:36
Build a dark mode light mode in reactjs with context api
29:20
Hitesh Choudhary
Рет қаралды 32 М.
The Ultimate Sausage Prank! Watch Their Reactions 😂🌭 #Unexpected
00:17
La La Life Shorts
Рет қаралды 8 МЛН
When u fight over the armrest
00:41
Adam W
Рет қаралды 32 МЛН
СКОЛЬКО ПАЛЬЦЕВ ТУТ?
00:16
Masomka
Рет қаралды 3,5 МЛН
ТЮРЕМЩИК В БОКСЕ! #shorts
00:58
HARD_MMA
Рет қаралды 2,7 МЛН
Light / Dark Mode Toggle In React Tutorial
16:02
PedroTech
Рет қаралды 101 М.
How To Build An Advanced Light/Dark Theme Toggle
25:46
Web Dev Simplified
Рет қаралды 89 М.
TailwindCSS Dark Mode UI with React App
19:49
For Those Who Code
Рет қаралды 9 М.
MUI V5: Themes (custom colors + fonts, dark mode, spacings, CSSbaseline)
22:50
NVIDIA’s New AI: Stunning Voice Generator!
6:21
Two Minute Papers
Рет қаралды 32 М.
React Dark Mode Toggle/Theme - Complete Guide
12:29
Code Complete
Рет қаралды 30 М.
Light / Dark mode theme toggle in React | Easy way
13:33
CodeCrunch
Рет қаралды 1,1 М.
Light Dark Mode React - Without Any Libraries
13:50
Monsterlessons Academy
Рет қаралды 8 М.
The Best Way to Handle Dark Mode with TailwindCSS
3:49
Tom Is Loading
Рет қаралды 30 М.
The Ultimate Sausage Prank! Watch Their Reactions 😂🌭 #Unexpected
00:17
La La Life Shorts
Рет қаралды 8 МЛН