From the course: Build Modern Web Apps with React, Hooks, State Management, and APIs Using Vite or Next.js

Unlock this course with a free trial

Join today to access over 25,200 courses taught by industry experts.

useContext introduction

useContext introduction

We are going to start off our lesson number 4 which will include the use context hook. We have discussed the use context hook before as well in the previous lessons where we did an example. In this video, we are going to understand it in more detail. So let's recall what is context in react. It's a way to pass data deeply through the component tree without manually passing the props. If you remember, we did an example that where we were doing prop drilling, which can have so many problems in our application and to avoid prop drilling, we get to have a solution that is creating a context which serves as a shared state throughout the application. It's a great example when you have a global state use cases like theming, authentication or user's preferences. It's usually built with two main parts that includes the create context function which actually creates your context and then your use context hook which allows you to consume this. Let's walk through an example where we are going to…

Contents