What is the use of React Context in React-Redux?
Last Updated :
23 Jul, 2025
React Context is a feature that React provides us to manage states required in multiple components. Redux is also a state management library and solves the same problem that React Context does but in a different way. In this article, we will see in detail what is react context, why and how to use it, how it is related to and different from react-redux, and then at last we'll see which one to use and when.
What is React Context?
React Context creates a new data layer apart from virtual DOM, to make states and data easily accessible to all the components. That means if any component wants to access some data, it can subscribe to context and use or update the data as per its requirement. Whenever any state in the context gets updated by any component, all the components that are subscribed to context re-render automatically.
But wait! Why we are using react context? Are states and props not enough to handle data in our project?
Why to use React Context?
React Context solves two major problems that using state and props can't be solved.
Suppose we have to pass data from the parent component to its grandchild, what do we generally do? we pass data as props from parent to its child and then from child, we pass data as props to its grandchild. In this whole scenario child does not need that data but still, it is becoming a bridge to connect parent and grandchild.
This passing of props from higher-level components to deeply nested components using intermediate components is basically prop drilling. Prop drilling can cause performance issues because when the prop changes, intermediate components will also re-render unnecessarily and prop drilling also makes the code less maintainable.
2. Helps in Lifting the state up
Lifting the state up means if the sibling components want to share data using a common state then we have to declare that state in the parent component of all the siblings, as there is no other way to connect siblings. Since we are lifting the state from a lower level to a higher level, we call this lifting the state up.
Parent
/ \
Child1 Child2 - Siblings
React Context works as a centralized store from where any component can access the state they want. That means we don't need to pass props using prop drilling. This is how React Context helps in avoiding props drilling, and make code more maintainable and also prevents unnecessary re-renders caused by prop drilling.
How to set up React Context?
Follow these simple steps to set up react context in a new react project.
Step 1: Create a react project folder, open the terminal, and write the following command.
# Run this to use npm
npx create-react-app foldername
# Or run this to use yarn
yarn create react-app foldername
Step 2: Navigate to the root directory of your project using the following command.
cd foldername
Step 3: Creating a Context
We can create context by using the createContext() method given by React. See the below code snippet.
// Creating a context
import { createContext } from "react"
const AppContext = createContext();
The best practice is to create a separate folder named "context" and there you can create any number of contexts.
Step 4: Providing Context to Components
All those components that want to use data from the context must wrapped around the Context Provider.
// Providing the Context
const App = () => {
return (
<AppContext.Provider value={/* your shared value */}>
{/* Components that can access the context value */}
</AppContext.Provider>
);
}
Step 5: Using Context in Component
To use data from context, a component can use the "useContext" hook provided by React.
const Child = () => {
const contextValue = useContext(AppContext);
}
That's how we can use Context in the React project.
How React Context is related to React-Redux?
Both react context and react-redux can be used for managing the state in the react app. They have similarities and difference both.
- As we create Context we can create a store in redux and useContext also works similarly to useSelector in redux.
- React Context re-renders all the components that are using the context value on any state change which results in performance issues. But in redux, only those components re-renders whareis subscribed to the particular state.
- In terms of usage, React Context is easier to learn and simpler to set up whereas react redux is a bit difficult for beginners and complex to set up.
- We can create multiple contexts in the react app but we have only one store while using redux.
What to use and When?
Deciding which one to use depends on multiple factors like the size and complexity of the app. So, use React Context when you have simple state management and your app size is smaller and Redux comes in handy when you have complex state management and the app size is bigger.
Similar Reads
React Tutorial React is a powerful JavaScript library for building fast, scalable front-end applications. Created by Facebook, it's known for its component-based structure, single-page applications (SPAs), and virtual DOM,enabling efficient UI updates and a seamless user experience.Note: The latest stable version
7 min read
React Fundamentals
React IntroductionReactJS is a component-based JavaScript library used to build dynamic and interactive user interfaces. It simplifies the creation of single-page applications (SPAs) with a focus on performance and maintainability. Why Use React?Before React, web development faced issues like slow DOM updates and mes
7 min read
React Environment SetupTo run any React application, we need to first setup a ReactJS Development Environment. In this article, we will show you a step-by-step guide to installing and configuring a working React development environment.Pre-requisite:We must have Nodejs installed on our PC. So, the very first step will be
3 min read
React JS ReactDOMReactDOM is a core React package that provides methods to interact with the Document Object Model, or DOM. This package allows developers to access and modify the DOM. It is a package in React that provides DOM-specific methods that can be used at the top level of a web app to enable an efficient wa
3 min read
React JSXJSX stands for JavaScript XML, and it is a special syntax used in React to simplify building user interfaces. JSX allows you to write HTML-like code directly inside JavaScript, enabling you to create UI components more efficiently. Although JSX looks like regular HTML, itâs actually a syntax extensi
5 min read
ReactJS Rendering ElementsIn this article we will learn about rendering elements in ReactJS, updating the rendered elements and will also discuss about how efficiently the elements are rendered.What are React Elements?React elements are the smallest building blocks of a React application. They are different from DOM elements
3 min read
React ListsIn lists, React makes it easier to render multiple elements dynamically from arrays or objects, ensuring efficient and reusable code. Since nearly 85% of React Projects involve displaying data collections- like user profiles, product catalogs, or tasks- understanding how to work with lists.To render
4 min read
React FormsForms are an essential part of any application used for collecting user data, processing payments, or handling authentication. React Forms are the components used to collect and manage the user inputs. These components include the input elements like text field, check box, date input, dropdowns etc.
5 min read
ReactJS KeysA key serves as a unique identifier in React, helping to track which items in a list have changed, been updated, or removed. It is particularly useful when dynamically creating components or when users modify the list. the When rendering a list, you need to assign a unique key prop to each element i
4 min read
Components in React
React ComponentsIn React, React components are independent, reusable building blocks in a React application that define what gets displayed on the UI. They accept inputs called props and return React elements describing the UI.In this article, we will explore the basics of React components, props, state, and render
4 min read
ReactJS Functional ComponentsIn ReactJS, functional components are a core part of building user interfaces. They are simple, lightweight, and powerful tools for rendering UI and handling logic. Functional components can accept props as input and return JSX that describes what the component should render.Stateless (before hooks)
5 min read
React Class ComponentsClass components are ES6 classes that extend React.Component. They allow state management and lifecycle methods for complex UI logic.Used for stateful components before Hooks.Support lifecycle methods for mounting, updating, and unmounting.The render() method in React class components returns JSX el
4 min read
ReactJS Pure ComponentsReactJS Pure Components are similar to regular class components but with a key optimization. They skip re-renders when the props and state remain the same. While class components are still supported in React, it's generally recommended to use functional components with hooks in new code for better p
4 min read
ReactJS Container and Presentational Pattern in ComponentsIn this article we will categorise the react components in two types depending on the pattern in which they are written in application and will learn briefly about these two categories. We will also discuss about alternatives to this pattern. Presentational and Container ComponentsThe type of compon
2 min read
ReactJS PropTypesIn ReactJS PropTypes are the property that is mainly shared between the parent components to the child components. It is used to solve the type validation problem. Since in the latest version of the React 19, PropeTypes has been removed. What is ReactJS PropTypes?PropTypes is a tool in React that he
5 min read
React Lifecycle In React, the lifecycle refers to the various stages a component goes through. These stages allow developers to run specific code at key moments, such as when the component is created, updated, or removed. By understanding the React lifecycle, you can better manage resources, side effects, and perfo
7 min read
React Hooks
Routing in React
Advanced React Concepts
React Projects