Build a dark mode light mode in reactjs with context api

Поділитися
Вставка
  • Опубліковано 12 вер 2024
  • In this tutorial, we will guide you on how to build a dark mode and light mode feature in ReactJS using the Context API. This approach involves creating a custom hook that simplifies the process of managing and toggling themes across your application. We’ll start by setting up a new React project with Tailwind CSS for styling, which comes with built-in dark mode classes. The tutorial walks through the creation of a ThemeProvider to manage the theme state, along with functional components like a ThemeButton and a Card. The useContext and useEffect hooks are utilized to ensure that the theme toggles correctly, based on user interaction. This method is a clean, scalable way to handle themes, especially useful for small to mid-size projects. Understanding how to leverage the Context API and custom hooks in React will not only streamline your development process but also improve code maintainability. Whether you are a beginner or an experienced developer, this guide will provide you with the essential skills to implement dark/light mode efficiently in your React applications.
    Welcome to a youtube channel dedicated to programming and coding related tutorials. We talk about tech, write code, discuss about cloud and devops. That’s what we do all day, all year. We roll out a lot of series and videos on our channel.
    All the learning resources such as code files, documentations, articles and community discussions are available on our website:
    chaicode.com/
    You can find our discord link, github link etc on the above website.
    Twitter/X link: x.com/hiteshdo...
    Discord link: hitesh.ai/discord
    Learn React with 10 projects: • Let's learn react from...
    Learn Docker: • A practical guide on D...
    Learn Kubernetes: • Complete Kubernetes Co...
    How does a browser works: • How does a browser wor...
    How nodejs works: • How node JS works | En...
    Learn Redux-toolkit: • Learn Redux Toolkit in...
    Learn NextJS: • Nextjs Full stack course
    Learn Typescript: • Why to learn Typescript
    Learn Javascript: • Welcome to new JavaScr...
    Learn React Native: • React Native Mastery: ...
    Learn Zustand: • React state management...
    Learn Golang: • How to get started wit...

КОМЕНТАРІ • 172

  • @aimenazim1508
    @aimenazim1508 12 днів тому

    enjoying the series.

  • @TheZubbyShow
    @TheZubbyShow 11 місяців тому +2

    You are doing a good job, learning a lot from you. Kudos!

  • @bijendra4329
    @bijendra4329 13 днів тому

    Hi Hitesh, thanks much for simplifying and sharing this knowledge 🙏

  • @badalsahani112
    @badalsahani112 11 місяців тому +1

    Hitesh sir, you are the reason I started learning frontend. I was more of a backend person

  • @TheAremoh
    @TheAremoh 11 місяців тому +2

    I like your teach style.
    Thanks for all you do for the community

  • @deadlylive_gaming7154
    @deadlylive_gaming7154 2 дні тому

    Thanks, your motivation driving factor ✓ nailed the explanation well with 2 context api approaches 🎉

  • @ericjunior105
    @ericjunior105 28 днів тому

    You did good man, you did good.

  • @vosyasabesquien
    @vosyasabesquien 8 місяців тому +2

    Thanks hitech. Very clear explanation about context api. I just got one question: what if i want to have two (global) contexts in main app.jsx? lets say 'theme context' and 'toast context' for the whole webapp. Then we just need to nest those two providers in app.jsx? Like .....

  • @shyamnarayananj4480
    @shyamnarayananj4480 8 днів тому

    Thanks for the tutorial

  • @736939
    @736939 11 місяців тому +3

    Thank you Hitesh. It would be great to see TypeScript with React as well :)

    • @juanmacias5922
      @juanmacias5922 11 місяців тому +2

      I've been doing these projects in TS myself, not much changes, you just need to add some types when asked to lol

  • @tamoghnadey
    @tamoghnadey 5 місяців тому

    Your videos are great, having individual mini projects for each concept is very informative

  • @ishvarkanjariya2498
    @ishvarkanjariya2498 11 місяців тому

    Your presentation style is so engaging and informative. I've learned so much from watching your videos. Keep up the fantastic work

  • @brunohenrard
    @brunohenrard 3 місяці тому

    Again a great video !

  • @subuhifarooqui5165
    @subuhifarooqui5165 4 місяці тому

    thanks Hitesh Sir....I am trying to start my career after a very long career break.....Your videos helps alot ....🙂🙂🙂🙂🙂

  • @erbhargavvyas
    @erbhargavvyas 2 дні тому

    I got one question. Why we have to defin the functions in the App.jsx. If the functions are static then can't we define them directly in the context file?

  • @SreehariE-s2k
    @SreehariE-s2k Місяць тому

    thank you for the explanation 👏

  • @farzananipa1605
    @farzananipa1605 5 місяців тому

    Your videos made my developer journey easier

  • @serpercody5347
    @serpercody5347 11 місяців тому +1

    Thank you for the great explanation Hitesh.

  • @Gorav14
    @Gorav14 11 місяців тому

    i am waiting.. though i didn't watch the other videos of this series...sir i went through your vlogs and courses, your channel seems like it can change my future

  • @Shiv_kolekar
    @Shiv_kolekar 2 місяці тому

    Thankyou for explaining it so well

  • @nica1
    @nica1 8 місяців тому

    Thank you for all your hard work. You are helping so many people.

  • @pawankand
    @pawankand 11 місяців тому

    Thank you Hitesh for making this context api much eaiser to understand 🙂

  • @opencode1
    @opencode1 4 місяці тому

    hope you will make other videos like this, love it

  • @AliAhmed-vq8fi
    @AliAhmed-vq8fi 4 місяці тому

    Thank you sir for such an amazing tutorial

  • @brkrvisions780
    @brkrvisions780 11 місяців тому +2

    hi, I have a problem with my LCO account it is not showing my content, is it a server issue or what

    • @brkrvisions780
      @brkrvisions780 10 місяців тому +1

      Waiting for the reply

    • @brkrvisions780
      @brkrvisions780 10 місяців тому +1

      If any issues please release as soon as possible

    • @HiteshCodeLab
      @HiteshCodeLab  10 місяців тому

      It’s now managed by ineuron. Please reach out to query@ineuron.ai for assistance. They own it now. 🙂

  • @tanyaraj3129
    @tanyaraj3129 7 місяців тому

    left the comment cause your content is very helpful for me
    love you guruji

  • @aaronmanocha9158
    @aaronmanocha9158 2 місяці тому

    Thanks sir for providing this valuable content.

  • @ankushchavanwebdeveloper
    @ankushchavanwebdeveloper 10 місяців тому +3

    Subject: Request for a Micro Frontend Series
    Dear Hitesh Sir,
    I hope this message finds you well. I wanted to express a suggestion that I believe would greatly benefit our community of learners. Could you please consider creating a series on MicroFrontends? Such a series would undoubtedly prove to be immensely helpful for everyone eager to enhance their knowledge in this domain.
    Thank you for considering my request, and I look forward to hearing your thoughts on this matter.
    Best regards,
    Ankush Chavan

  • @juanmacias5922
    @juanmacias5922 11 місяців тому

    I was thinking that if you needed to use many stores, this could get a bit confusing, happy you acknowledged at the end that Redux Toolkit is favorable in those situations, haha great video though!

  • @Adventures_English
    @Adventures_English 8 місяців тому

    Very valuable videos. Thanks again, Hitesh!

  • @041_ponranjithm6
    @041_ponranjithm6 11 місяців тому +2

    Hitesh sir please come with multiple nested context with usereducer combination project bcoz in Internet most videos are just single context project humble request to you sir!!

  • @luce9574
    @luce9574 6 місяців тому +1

    Thankyou for such great quality content

  • @Bhaskarjyoti02
    @Bhaskarjyoti02 5 місяців тому

    Thankyou so much for this amazing tutorial, need a little bit time to absorb it

  • @vinothkumarv9722
    @vinothkumarv9722 3 місяці тому

    Great sir ❤❤❤❤❤

  • @marisankarm58
    @marisankarm58 Місяць тому

    Even though it is bit confusion for me, I will try to understand the need and usage of context api.

  • @albi712
    @albi712 11 місяців тому +2

    Hello Sir, not able to access our LCO courses. I have dropped couple of mails but no response from support team. There was no official mails notifying blocking our access. I have seen in the comments section few other people's also having same issues. If you see this message, could you please tell us what's happening.

    • @srikarkulakcherla2202
      @srikarkulakcherla2202 11 місяців тому +1

      Same with me, absolutely pathetic support.

    • @joebenterryk2050
      @joebenterryk2050 11 місяців тому

      @@srikarkulakcherla2202 I have the same issue. They are not even responding and its been weeks now

    • @SudhirVetri
      @SudhirVetri 10 місяців тому +1

      same issue for me as well, Please act quickly

    • @albi712
      @albi712 10 місяців тому

      @@SudhirVetri I don't think issue will be resolved. From what I learned, physics wallah bought INeuron and LCO. Since then access has been revoked. Don't think they will give the access. They just ruined the good platform.

    • @albi712
      @albi712 10 місяців тому

      @@SudhirVetri I don't think issue will be resolved. From what I learned, physics wallah bought INeuron and LCO. Since then access has been revoked. Don't think they will give the access. They just ruined the good platform.

  • @harishs1316
    @harishs1316 8 місяців тому

    Thank you so much for the amazing series learnt a lot🤞

  • @lordbeerus3310
    @lordbeerus3310 10 місяців тому

    Sir plz make 1hr videos it would better for us also sir till now the journey was amazing, hoping to do major projects with you

  • @dolfieaspeling9893
    @dolfieaspeling9893 8 місяців тому

    Keep going bro excellent series

  • @asingh5128
    @asingh5128 10 місяців тому

    i hvae taken the react js course on lco, but not able to login. i have also written several mails but no action taken

  • @murshid956
    @murshid956 11 місяців тому

    Really helpful, waiting for next video.

  • @ezgiozturan8014
    @ezgiozturan8014 2 місяці тому

    Thank you!!

  • @vamshi2nd392
    @vamshi2nd392 Місяць тому

    in react series why to use document.queryselector,

  • @rajeshseemakurthi1595
    @rajeshseemakurthi1595 9 місяців тому

    Awesome video for beginner Developers

  • @user-kg4ug5gz8u
    @user-kg4ug5gz8u 6 місяців тому

    love all your videos

  • @Adventures_English
    @Adventures_English 8 місяців тому

    Fun Fact: You can completely delete theme.js from the project and it still works fine. I imagine what was implented in App.jsx could also be moved into the object in theme.js?? Not quite following. Any insight greatly appreciated.

  • @AliAhmed-vq8fi
    @AliAhmed-vq8fi 3 місяці тому

    Thank you soooo much

  • @dineshmaurya7072
    @dineshmaurya7072 2 місяці тому

    good teaching method

  • @malikhaidi434
    @malikhaidi434 7 місяців тому

    Thank you for such a valuable content

  • @prasadpatil2371
    @prasadpatil2371 11 місяців тому

    second method is very helpful where we create, aware & use the method in single file.

  • @anuha6400
    @anuha6400 2 місяці тому

    Thank you

  • @H_R_D
    @H_R_D 9 місяців тому

    Thank you for your great content☺☺

  • @OlaMovies-pj3dy
    @OlaMovies-pj3dy 5 місяців тому

    Hitesh Paapi ❌Hitesh Choudhary✅

  • @Eric-sy3dm
    @Eric-sy3dm 8 місяців тому

    Thank you for the lesson ❤.

  • @rezamash83
    @rezamash83 7 місяців тому

    Awesome videos!!!

  • @ravianand6351
    @ravianand6351 10 місяців тому

    Using vanilla javascript code, inside React isn't recommended right ??

  • @avi933
    @avi933 11 місяців тому

    You are doing great work

  • @morecoinbull
    @morecoinbull 9 місяців тому

    hey man thanks for this video!!

  • @alihosaino7
    @alihosaino7 8 місяців тому +1

    Thank you❤❤

  • @praveshverma0808
    @praveshverma0808 6 місяців тому +1

    your are op sir

  • @amitbiswas54
    @amitbiswas54 11 місяців тому

    Do you have react js series? Like your js

  • @abhisheksankpal2
    @abhisheksankpal2 10 місяців тому +1

    Hey Hitesh I bought pro backend course from lco but currently not able to acess it , I have mailed you details please look into it

    • @HiteshCodeLab
      @HiteshCodeLab  10 місяців тому

      It’s now managed by ineuron. Please reach out to query@ineuron.ai for assistance. They own it now. 🙂

  • @Moto_memoirs_45
    @Moto_memoirs_45 9 місяців тому

    @hitesh, i just take some reference from your portfolio website, i found an ui related bug in your website in the video section, your video close btn is not working, thank you.

  • @rexraymond5039
    @rexraymond5039 11 місяців тому

    awesome explanation

  • @ok98730
    @ok98730 11 місяців тому +1

  • @pearl-jp4vd
    @pearl-jp4vd 8 місяців тому

    Why did we add this line
    darkMode: "class"
    in tailwind.config.js file at the end of the video ?
    What is the significance of this addition ?

    • @aadityapuri1061
      @aadityapuri1061 6 місяців тому

      did you get it bro? cauz I have same doubt

    • @pearl-jp4vd
      @pearl-jp4vd 6 місяців тому

      No bro , I hadn't researched after that. If you come across the explanation anywhere please let me know too.@@aadityapuri1061

  • @harshit2629
    @harshit2629 10 місяців тому

    Hi Sir, thank you for video, when I am trying to login into your app, it's showing it's blocked by admin, what's the reason? I tried multiple times Sir @ Hitesh Choudhary Sir

  • @ishaanbajaj2229
    @ishaanbajaj2229 10 місяців тому

    I am an unable to buy course from your official website

  • @btissamchaibi9015
    @btissamchaibi9015 8 місяців тому +1

    Where's the GitHub repository

  • @yuvrajmishra1588
    @yuvrajmishra1588 29 днів тому

    ❤❤❤

  • @AmitSaini-ew7ep
    @AmitSaini-ew7ep 4 місяці тому

    now im here

  • @debjit21
    @debjit21 11 місяців тому

    Frankly I enjoy "chai aur code" more.

  • @mujahidulislamshaikh9664
    @mujahidulislamshaikh9664 4 місяці тому +1

    Love you

  • @user-uv5or5bm2c
    @user-uv5or5bm2c Місяць тому

  • @fluteprograming
    @fluteprograming 29 днів тому

  • @yogeshjangid3696
    @yogeshjangid3696 11 місяців тому +1

    Hello Sir,
    Sorry I am disturbing you here, but I am not able to access my courses in LCO Platform. When I login with my account then it's shows that I can't access my course and contact admin. I mailed you and also raised a ticket in LCO platform but no response.
    May you please help me resolve this issue.
    #LCO ♥

    • @albi712
      @albi712 11 місяців тому +1

      PW just acquired LCO from ineuron. Its no longer in SIR's hands. I just came to know that now. We just lost a good content. Better look for something else.

    • @harshit2629
      @harshit2629 10 місяців тому

      ​@@albi712same here, not able to access on app through gmail

    • @-UPH-KRISHNAM
      @-UPH-KRISHNAM 10 місяців тому

      @@albi712 do you think Sir has no responsibility over my money just because I paid for it at the moment he was handling it? do you think that money was easy to earn? the money which I paid was my effort and time and energy, so easy of you to defend your sir. did he just handed over the platform for free?

    • @albi712
      @albi712 10 місяців тому

      @@-UPH-KRISHNAM just like you I paid for a course and was not able to access it. Sent out couple of mails but no response from anybody. Later I came to know a comment from SIRs Instagram account saying that not in their hands since it's been acquired by ineuron and sold it to someone else.

    • @albi712
      @albi712 10 місяців тому

      @@-UPH-KRISHNAM I m not defending anyone. Just that no one is taking responsibility for the money we paid for the course or access issues. Maybe u can try sending mails to support but no one is going to reply back.

  • @user-kk1vu9tz8g
    @user-kk1vu9tz8g 11 місяців тому

    hi hitesh from Turkey

  • @AnkitTanwarUPSC-eo6dk
    @AnkitTanwarUPSC-eo6dk 11 місяців тому

    Bhiya apse milna hi jecrc university mai I m in btech 1st year cse

  • @vedshrivastava9358
    @vedshrivastava9358 3 місяці тому

    👍👍👍👍

  • @anonlegion8331
    @anonlegion8331 7 місяців тому

    Thank You

  • @user-en1pd3zc7e
    @user-en1pd3zc7e 5 місяців тому

    Thanks a lot

  • @shubhamjangid5936
    @shubhamjangid5936 7 місяців тому

    EROOR -> darkTheme() is not triggering
    CODE ->
    function App({ children }) {
    const [themeMode, setThemeMode] = useState("light");
    const darkTheme = () => {
    console.log("darkTheme");
    setThemeMode("dark");
    document.body.setAttribute("data-theme", "dark");
    };
    const lightTheme = () => {
    setThemeMode("light");
    document.body.setAttribute("data-theme", "light");
    };
    return (



    {children}



    );
    }

  • @Ayushsharma-xn5hg
    @Ayushsharma-xn5hg 11 місяців тому

    Sir app to Japan m ho too app vha se live ho

  • @iBounty12
    @iBounty12 7 місяців тому

    Thanks again

  • @jeevananthamn7532
    @jeevananthamn7532 9 місяців тому

    good, thank you

  • @ManasPant-gf3jv
    @ManasPant-gf3jv 8 місяців тому

    Awesome

  • @not_amanullah
    @not_amanullah 5 місяців тому

    Thanks ❤

  • @KnowledgeBoxMM
    @KnowledgeBoxMM 21 день тому

    ❤🎉

  • @user-oh8iq3do4u
    @user-oh8iq3do4u 10 місяців тому

    great

  • @Hatsoff4u
    @Hatsoff4u 9 місяців тому

    awesome

  • @Ashutosh_Kumar17
    @Ashutosh_Kumar17 4 місяці тому

    Lijiye sir kr diya comment

  • @samirrobin3524
    @samirrobin3524 11 місяців тому

    Thank you so much❤❤

  • @sanjaysingh-bs7oy
    @sanjaysingh-bs7oy 2 місяці тому

    🥰

  • @ShubhamSharma-nr7kw
    @ShubhamSharma-nr7kw 4 місяці тому

    just leave a comment

  • @birendrabohara959
    @birendrabohara959 11 місяців тому

    Outstanding

  • @salmanfarshisajib6512
    @salmanfarshisajib6512 7 місяців тому

    Nice👍

  • @CodeNageShorts
    @CodeNageShorts 6 місяців тому

    nice

  • @srinivaspoosa8606
    @srinivaspoosa8606 10 місяців тому

    superbb

  • @jgappy
    @jgappy 7 місяців тому

    🌎

  • @nakshathra29
    @nakshathra29 3 місяці тому

    👋👍