Light / Dark Mode Toggle In React Tutorial

แชร์
ฝัง
  • เผยแพร่เมื่อ 28 ก.ค. 2024
  • In this video I will show how to make a Dark Mode / Light Mode toggle switch using ReactJS.
    Code: github.com/machadop1407/dark-...
    Codepen: codepen.io/Devel0per95/pen/rj...
    Join our Discord: / discord
    🚀 Learn ReactJS By Building 6 Projects: codedamn.com/learn/reactjs-pr...
    🐙 GraphQL Course: codedamn.com/learn/graphql-fo...
    ► Buy Crypto on Coinbase: coinbase-consumer.sjv.io/PedroTech
    Social
    ▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬
    Website: machadopedro.com
    Linkedin: / machadop1407
    Instagram: / _pedro.machado_
    Github: github.com/machadop1407
    Business Email: pedro@pedrotech.co
    Tags:
    - ReactJS Tutorial
    - ReactJS and MySQL
    - NodeJS Tutorial
    - API Tutorial
    06:26 | UI Introduction
    08:44 | Creating the Context
    16:18 | Adding customizable features
    #reactjs #coding
  • วิทยาศาสตร์และเทคโนโลยี

ความคิดเห็น • 101

  • @walterbranco8798
    @walterbranco8798 2 ปีที่แล้ว +16

    Sempre com videos práticos e direto ao ponto. Valeu, Pedro!

  • @PandaLaVeraa
    @PandaLaVeraa 2 ปีที่แล้ว +2

    That was fire! Super efficient and definitely using SCSS with it helped a bit, organizing. Definitely subscribing!

  • @ThColinPereira
    @ThColinPereira 2 ปีที่แล้ว +2

    the editing of your videos has improved so much!

  • @voldemortvi4264
    @voldemortvi4264 2 ปีที่แล้ว +2

    Dont stop uploading , i love your videos ! thank you !!

  • @Smartercow
    @Smartercow 2 ปีที่แล้ว +4

    Man your recent uploads have been good! Exactly what I want! Keep it up!

    • @PedroTechnologies
      @PedroTechnologies  2 ปีที่แล้ว +1

      Hahaha I've been doubling my time with each video! Glad you are liking them :)

  • @ko3ak112
    @ko3ak112 ปีที่แล้ว

    Dont worry bro. The explanation was pretty clear. We don't have any idea how cool you really are. Thanks 🙏

  • @ndahayokevin7626
    @ndahayokevin7626 2 ปีที่แล้ว +1

    Exactly we needed it much ! thanks Pedro

  • @MiikaKontio
    @MiikaKontio ปีที่แล้ว

    Great tutorial. This helped me to quickly build dark theme for my react application

  • @egzongallapeni8098
    @egzongallapeni8098 2 ปีที่แล้ว +16

    Man this is catching 2 birds with 1 stone basically explaining contextApi and toggle .Bless you man

    • @PedroTechnologies
      @PedroTechnologies  2 ปีที่แล้ว +3

      Hahaha Glad you liked it! Although I wanted the code to look simple, I knew that anyone who wanted to do this in their website would eventually have to manage their states.

  • @AnshumanBisoyi
    @AnshumanBisoyi ปีที่แล้ว +1

    You are my favorite coder-teacher-youtuber.

  • @arjun-de6dr
    @arjun-de6dr 2 ปีที่แล้ว +3

    At the right time pedro 🙂, I was thinking of it and then your video pops up.
    This will help me a lot.
    Thanks man!!

  • @pushin.P
    @pushin.P 6 หลายเดือนก่อน

    Thank you so much Pedro! you went straight to the point and explained everything pretty easy!

  • @adimishra3046
    @adimishra3046 2 ปีที่แล้ว +11

    Sometimes I think u keep a track of what should I learn next... 😜thanks for the video brother you never disappoint... highly appreciate your quality work and love from India ❤️❤️

    • @PedroTechnologies
      @PedroTechnologies  2 ปีที่แล้ว +2

      Hahaha glad to hear it! I always try to follow recommendations from my subs :)

  • @user-jf9sm8nc8y
    @user-jf9sm8nc8y ปีที่แล้ว

    Thanks a lot for this video!! I'm really happy to do it so quickly 😍

  • @trigga3085
    @trigga3085 2 ปีที่แล้ว

    Your videos are so good. Thank you, man

  • @vitorzbr9013
    @vitorzbr9013 ปีที่แล้ว

    Mate... Awesome tutorial, keep up with the content!

  • @stephontreadwell1664
    @stephontreadwell1664 ปีที่แล้ว

    DAMN Pedro! This was a dope tutorial. Thank you so much!

  • @ujjvalw2684
    @ujjvalw2684 2 ปีที่แล้ว +1

    Very useful video... Good stuff man

  • @sarthaksrivastava6245
    @sarthaksrivastava6245 2 ปีที่แล้ว

    Thanks pedro! I really liked your explanation.

  • @mohamedlaraiche7319
    @mohamedlaraiche7319 2 ปีที่แล้ว +1

    You are incredible ^^ thank you for this valuable content

  • @zekeriyacinal3007
    @zekeriyacinal3007 3 หลายเดือนก่อน

    This was really helpful, thank you for the video!

  • @universecode1101
    @universecode1101 2 ปีที่แล้ว +3

    Nice ✌🏻this is very helpful

  • @anuragchindaliya
    @anuragchindaliya 2 ปีที่แล้ว +4

    Css variables work like charm for theme modes

  • @gonsalomon
    @gonsalomon 2 ปีที่แล้ว +1

    The fact you got Copilot running helps it to be more approachable. I can't live without it, so it's astonishing there's a dev with more experience who also uses it. Thank you!

    • @Dedition
      @Dedition 2 ปีที่แล้ว

      Hopefully this isn't still true for you.

  • @serghaouiyoussef962
    @serghaouiyoussef962 2 ปีที่แล้ว +1

    Awesome video!
    I do think that using SCSS would make things a little bit cleaner.
    cheers 👌👌

  • @bilalch898
    @bilalch898 2 ปีที่แล้ว +3

    Pretty easy and much more flexible with Mui as you won't need to keep record of each element id or classes and manage their styles individually.

  • @mabrarhassan
    @mabrarhassan ปีที่แล้ว

    Wonderful and entertaining as well as informative video I just enjoyed watching.

  • @cristiankeibersbardelotto
    @cristiankeibersbardelotto ปีที่แล้ว

    Thank you! It will help me so much!

  • @piotrszczesniak685
    @piotrszczesniak685 ปีที่แล้ว

    Perdo, you have become my best resource to learn React 👋👋🙋‍♂🙋‍♂💪💪🔥🔥

  • @alexissantaana3908
    @alexissantaana3908 ปีที่แล้ว

    Great tutorial. Subscribed.

  • @alexandreluiz6182
    @alexandreluiz6182 ปีที่แล้ว

    Thanks Pedro! That was very helpful. How can I save the theme on localStorage in order to save the user's preference?

  • @danielrondongarcia9905
    @danielrondongarcia9905 ปีที่แล้ว

    Perfect video! Thanks!!

  • @okpanumebuka2862
    @okpanumebuka2862 ปีที่แล้ว +1

    God bless you!!
    Please if I want the toggle to be an image like a sun ☀️ for light and moon 🌙 for dark how can I do that

  • @gavinwalsh8417
    @gavinwalsh8417 ปีที่แล้ว

    Great Video! very helpful

  • @franciscosoares4128
    @franciscosoares4128 2 ปีที่แล้ว +1

    Can u please make a video explaining how to record an audio and storing into firestore??Would appreciate that!
    Love the content

  • @amateruss
    @amateruss ปีที่แล้ว +1

    You can just use setTheme(!theme) inside your toggleTheme function, right?

  • @aritnath151
    @aritnath151 ปีที่แล้ว +1

    Hey there, wanted to ask,
    If we have multiple pages in a webpage, How to convert that entirely ??

  • @NotDead10008
    @NotDead10008 2 ปีที่แล้ว +3

    The best react channel.

  • @berkaysenoglu1784
    @berkaysenoglu1784 6 หลายเดือนก่อน

    how can I change body background color depending on theme?

  • @kashmirtechtv2948
    @kashmirtechtv2948 2 ปีที่แล้ว +1

    Intro 🔥

  • @Messi2Inno
    @Messi2Inno 2 ปีที่แล้ว

    Hey! Pedro, you mind doing a video with golang as backend and react as frontend with SQL database??

  • @joshdelacruz-tm6lg
    @joshdelacruz-tm6lg ปีที่แล้ว

    how can i change the size and height if i use media query? className doesnt work to react-switch

  • @AkashGupta-rw4vm
    @AkashGupta-rw4vm 2 ปีที่แล้ว +5

    One of the best solution to change the styles of different components according to the theme is by using css custom properties and just change those custom property according to theme and it will be reflected to the whole website.
    Hope this helps 😌😌

    • @jesuschristimsmall
      @jesuschristimsmall 2 ปีที่แล้ว

      can you expand on this please? or did you have any exmaples of code

  • @EmiStruggles
    @EmiStruggles 10 หลายเดือนก่อน

    Hi, thanks for the help, if anyone's background color is not dynamic, check your root in css, that's probably the problem.

  • @RazmonTheArtist
    @RazmonTheArtist ปีที่แล้ว

    how would I pass the themes to other components?

  • @nikako1889
    @nikako1889 2 ปีที่แล้ว

    which theme do u use?

  • @njourawebdev
    @njourawebdev ปีที่แล้ว

    thank man really appreciate it

  • @ricardohernandez8033
    @ricardohernandez8033 ปีที่แล้ว

    Perfect job, thanks....

  • @friendlyapk
    @friendlyapk 2 ปีที่แล้ว +1

    Toggle is resetting or triggering twice for some reason! Why!

  • @minsungsuh3872
    @minsungsuh3872 ปีที่แล้ว

    Thank you so much!

  • @shashwattulsyan8522
    @shashwattulsyan8522 2 ปีที่แล้ว +1

    hey can you please make a seperate video form storing user details along with files like image and pdf in mongoDB(MERN).

  • @rovio_3365
    @rovio_3365 8 หลายเดือนก่อน

    That was awesome ! But I encountered a problem . How can i toggle it using a component which is inside a header that his inside tha app.js . I don't know how to do it I'm totally new .

  • @juancarlosrodriguez1085
    @juancarlosrodriguez1085 หลายเดือนก่อน +1

    Great!…as always!…

  • @lukamatovic8302
    @lukamatovic8302 ปีที่แล้ว

    How to make this using CSS modules instead of global CSS like in the video?

  • @ivan4486
    @ivan4486 6 หลายเดือนก่อน

    I suggest putting colors into CSS variables and make two sets of those vars - for a light and a dark theme. It would spare you rewriting styles for all elements.

  • @markomatic8459
    @markomatic8459 6 หลายเดือนก่อน

    👏saved my time💪

  • @CGAR_420
    @CGAR_420 10 หลายเดือนก่อน

    The way ive been doing dark mode now is setting default color variables in my root CSS.
    Then i change the value of those root css variables for each theme.
    Then it's easy to add more themes later since every component will use color: var(--buttonColor1)
    You just keep redefining --buttonColor1

  • @diaael-din8832
    @diaael-din8832 2 ปีที่แล้ว

    ty that was helpful

  • @abhaytiwari6411
    @abhaytiwari6411 2 ปีที่แล้ว +3

    Nice 😎👍

  • @dongnez
    @dongnez 2 ปีที่แล้ว +2

    I wanna answer because i change css var() in the index with document.document.element.style.setProperty and use a toggle to make theme change and i wanna know if that is right

    • @PedroTechnologies
      @PedroTechnologies  2 ปีที่แล้ว

      If it works then you can do that, although I would avoid accessing the document in react

  • @aniketbhalla1521
    @aniketbhalla1521 2 ปีที่แล้ว +1

    That's great, but if we purge our CSS to increase performance of website? We will no longer have access to styling in the opposite mode.

    • @gonsalomon
      @gonsalomon 2 ปีที่แล้ว

      I guess you can use inline styling, pre-set from the JS itself (or if you generate your page on a server, make the algorithm generating the code to also include that styling on it). It wouldn't affect performance since styling is quite lowweight, compared to a database request which could lag your page quite much more.

  • @felixl8961
    @felixl8961 2 ปีที่แล้ว +1

    Good video. I am just thinking the context is not necessary in this example. The state is already enough. Maybe you should expand the example to include the usage of context

  • @ujjvalw2684
    @ujjvalw2684 2 ปีที่แล้ว +1

    How do I deploy a full stack meen app for free? Like a college project? Any free solution? Ik GPages for react but what about server

  • @calarcher4869
    @calarcher4869 2 ปีที่แล้ว

    If you refresh the page in dark mode in your example, it will turn it back to light mode

  • @cnoot
    @cnoot 6 หลายเดือนก่อน

    nice video i learn a lot from it but i have one problem that i struggle and cant pass it even with stackoverflow, ai etc. help.
    so basically i need to put my reactswitch in exactly position in but how to make it funcional to toggle in header has a funcionality in the whole app.jsx. if anyone has some solution for it i ll be very thankfull :D

  • @abdulmomin-yq4mt
    @abdulmomin-yq4mt ปีที่แล้ว

    tnxxx🥰

  • @user-is8cm9qr9n
    @user-is8cm9qr9n หลายเดือนก่อน

    thank you

  • @oneManDev
    @oneManDev 2 ปีที่แล้ว

    But how do I save the theme to localStorage using useEffect hook?

  • @adegbuluayomiposi5478
    @adegbuluayomiposi5478 ปีที่แล้ว

    Thanks

  • @jasoncarzano9388
    @jasoncarzano9388 ปีที่แล้ว

    Why my children components not affecting to dark mode? Anyone can help me plzz?

  • @vicenzofrusciante5996
    @vicenzofrusciante5996 7 หลายเดือนก่อน

    é brasileiro esse pedro ai? parabens pela coragem

  • @fernandofeks2918
    @fernandofeks2918 8 วันที่ผ่านมา

    Mano seu inglês é absurdo de bom

  • @sunilmg723
    @sunilmg723 2 ปีที่แล้ว +2

    how to do same thing using styled component

    • @PedroTechnologies
      @PedroTechnologies  2 ปีที่แล้ว

      I definitely can :) With styled components it would be even easier hahaha

    • @sunilmg723
      @sunilmg723 2 ปีที่แล้ว

      @@PedroTechnologies Waiting for that video bro😍😍

  • @regilearn2138
    @regilearn2138 2 ปีที่แล้ว

    Please create Next.js/REST API/Typescript/Tailwind CSS/Prisma/PostgreSQL stack for next project

  • @abrarahmed6935
    @abrarahmed6935 2 ปีที่แล้ว +1

    redux toolkit , redux thunk complete video please .. 🙏😅

  • @braumski2
    @braumski2 7 หลายเดือนก่อน

    Man I was working on this for so many hours... I just had some CSS syntax wrong the whole time. Dear lord I'm sad

  • @melodia6875
    @melodia6875 หลายเดือนก่อน

    Bom vídeo. VAI BRASIL!

  • @tkot7857
    @tkot7857 ปีที่แล้ว

    11:04 to add switch

  • @cocoon1538
    @cocoon1538 ปีที่แล้ว

    It's a purple mode

  • @PatalJunior
    @PatalJunior ปีที่แล้ว

    This isn't ideal, instead of doing multiple background colors, just create some css variables and change their values depending on light or dark mode.
    I feel like it would be better, and easier to understand.

  • @it.b.10.mayoormoolya69
    @it.b.10.mayoormoolya69 ปีที่แล้ว

    10:04

  • @alexwood4426
    @alexwood4426 ปีที่แล้ว

    what is life

  • @abulazaiemabas5070
    @abulazaiemabas5070 2 ปีที่แล้ว

    Im really sorry, couldn't finish the video

  • @abulazaiemabas5070
    @abulazaiemabas5070 2 ปีที่แล้ว

    Dude!!!, Start using typescript, this is ugly🤢

    • @PedroTechnologies
      @PedroTechnologies  2 ปีที่แล้ว +6

      I use javascript for personal projects, but why would i ignore most of the beginner developers who still haven't learned typescript? My channel isn't just for me, its for my viewers. I do prefer to code with typescript, but I have to think about my subscribers who don't know it.

    • @hiwotina26
      @hiwotina26 2 ปีที่แล้ว

      Very helpful for beginners! Thanks 🙏🙏🙏

  • @cryptonicchronic8111
    @cryptonicchronic8111 2 ปีที่แล้ว +2

    youre awesome bro!!!! get a discord or telegra, channel love to chat with ya! thanks again!

  • @Messi2Inno
    @Messi2Inno 2 ปีที่แล้ว

    Hey! Pedro, you mind doing a video with golang as backend and react as frontend with SQL database??