React Project: Creating a dark mode toggle using the Context API

preview_player
Показать описание
In this tutorial, we’ll take a look at the Context API in React by building a simple app that can toggle between light and dark mode.

React Project: Creating a dark mode toggle using the Context API
---------------------------------------------------------------------------------------------------------
00:00 Introduction

00:22 Project overview
02:02 Creating components
05:31 CSS Layout
08:11 Creating the Context
10:02 Getting the Context
10:55 Toggling Light / Dark mode
14:51 Accessing context in nested components (setting the theme)
23:11 Wrap-up

— Follow Me —
— Thanks! —

So in this React Project we’ll be creating a small app (just a few components) that allows the user to toggle between light and dark mode.

The real point of the tutorial though is to learn about the Context API and how you can use it to wrap certain components in a ‘context’ which can then access a shared state, in our case whether the app is in ‘light’ or ‘dark’ mode.

We’ll start off by creating the components for our app and then we’ll apply some basic CSS layout styles.

Once setup, we’ll look at how to use the Context API with React by creating a context and then wrapping the components (the entire app for us) in a Context Provider.

We’ll then take a look at how we can access the context from within our React header component and then look at how to toggle the light / dark mode state which leads us on to applying the theme within the sub components.

So hopefully by the end of the tutorial you’ll have a good idea as to what the Context API is and how you could make use of it to share state in your apps!

#react #contextapi Channel Handle @codebubb
Рекомендации по теме
Комментарии
Автор

this gave me a good understanding of context API, thank you

bharatsn
Автор

This video was really helpful for my project. Thanks, dude!

naveenjoe
Автор

Thanks a lot I don’t know how to thank you your videos are so good and you start asap

atharvabhosale
Автор

This is awesome and well explained!....Thanks!👍

abdulsamadusman
Автор

Thank you! And what about <body> background color? How can i reach em?

ivanudodenko
Автор

Well explained. But, is there any advantage of using .jsx instead of .js extension?

bhagabatiprasad
Автор

Hey! Thanks for the tutorial! I hope you can help me with some minor problems!
I've followed this instruction to match my project, but I'm having problems with:
1. I have card with <h3> text, and <p> text i want to have different colours, how can i make that happen when i only define color once? (i.e i want to change colors like the css file, or maybe even in the css file if I can access it from there?)
2. I get white margins with darkmode. I have fixed this most placed by using padding instead, but some places I need margins, but i still want darkmode, how can i make that happen?

olavutneskjeldal
Автор

Hey, can you do a react-redux tutorial?

amalmohan
welcome to shbcf.ru