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.

Best practices

Best practices

Welcome back, in this video we are going to see what are the best practices while using the context API. The very first practice that we should be following is the use of having multiple separate context for your code. If you are going to have a need to use the context API inside multiple parts or multiple segregated data of your application, then you should always be doing multiple small contexts. For example, in the authentication context, we can have the details related to the user information who is logged in. And for theme context, we can have the theme based information. Similarly, we can have an application configuration context as well as language context. So, always avoid having one single context and putting everything inside it. You should always be breaking things down and keeping things following a single responsibility principle. The next point is related to what we should be keeping inside the context. So we should always consider things to put inside our context, which…

Contents