codingstuff.io
ExploreTutorialsProblemsCS Subjects
Get Started
ExploreTutorialsProblemsCS Subjects
Get Started
codingstuff.io

Master the art of building software through interactive tutorials, real-world problems, and guided projects.

Pune, Maharashtra, India

codingstuffmail@gmail.com

Product

  • Explore
  • Tutorials
  • Problems
  • CS Subjects

Company

  • About
  • Contact
  • Privacy Policy
  • Terms & Conditions
  • Sitemap

© 2026 codingstuff.io. All rights reserved.

Built with ❤️ for developers everywhere

/
/
All Tutorials
⚛️

React.js

32 / 61 topics
28Introduction to Redux29Creating a Redux Store30Actions and Reducers in Redux31Middleware in Redux32Integrating React with Redux33Handling Async Actions with Redux Thunk34Introduction to Redux Saga35Using Saga Effects in Redux Saga
Tutorials/React.js/Integrating React with Redux
⚛️React.js

Integrating React with Redux

Updated 2026-04-20
3 min read

Integrating React with Redux

In this section, we will explore how to integrate React with Redux for state management. Redux is a predictable state container for JavaScript apps, and it works excellently with React due to its unidirectional data flow and centralized store.

What is Redux?

Redux is a library that helps manage the state of your application in a predictable way. It uses a single immutable state tree that is updated through actions and reducers. This makes debugging and testing easier because the state changes are consistent and can be traced back to specific actions.

Key Concepts

  1. Store: The global state object that holds all the data for your application.
  2. Actions: Plain JavaScript objects that describe what happened in your application.
  3. Reducers: Functions that specify how the application's state changes in response to actions sent to the store.

Setting Up Redux with React

To integrate Redux with a React application, you need to install the necessary packages and set up the store, reducers, and actions.

Step 1: Install Required Packages

First, you need to install redux and react-redux. You can do this using npm or yarn:

npm install redux react-redux

or

yarn add redux react-redux

Step 2: Create the Redux Store

Create a new file called store.js in your project's root directory. This file will contain the configuration for your Redux store.

// src/store.js
import { createStore } from 'redux';
import rootReducer from './reducers';

const store = createStore(rootReducer);

export default store;

Step 3: Create Reducers

Reducers are functions that take the current state and an action, and return a new state. Let's create a simple reducer for managing a counter.

// src/reducers/counter.js
const initialState = {
  count: 0,
};

function counterReducer(state = initialState, action) {
  switch (action.type) {
    case 'INCREMENT':
      return { ...state, count: state.count + 1 };
    case 'DECREMENT':
      return { ...state, count: state.count - 1 };
    default:
      return state;
  }
}

export default counterReducer;

Step 4: Combine Reducers

If you have multiple reducers, you can combine them using combineReducers.

// src/reducers/index.js
import { combineReducers } from 'redux';
import counterReducer from './counter';

const rootReducer = combineReducers({
  counter: counterReducer,
});

export default rootReducer;

Step 5: Provide the Store to React

To make the Redux store available to your React components, you need to wrap your application in a Provider component from react-redux.

// src/index.js
import React from 'react';
import ReactDOM from 'react-dom';
import { Provider } from 'react-redux';
import App from './App';
import store from './store';

ReactDOM.render(
  <Provider store={store}>
    <App />
  </Provider>,
  document.getElementById('root')
);

Connecting React Components to Redux

Now that you have set up the Redux store, you can connect your React components to it. This allows your components to access the state and dispatch actions.

Step 1: Create Action Creators

Action creators are functions that return action objects. They make your code cleaner and more maintainable.

// src/actions/counter.js
export const increment = () => ({
  type: 'INCREMENT',
});

export const decrement = () => ({
  type: 'DECREMENT',
});

Step 2: Connect Components

You can connect your components to the Redux store using the connect function from react-redux.

// src/components/Counter.js
import React from 'react';
import { connect } from 'react-redux';
import { increment, decrement } from '../actions/counter';

const Counter = ({ count, increment, decrement }) => {
  return (
    <div>
      <h1>Count: {count}</h1>
      <button onClick={increment}>Increment</button>
      <button onClick={decrement}>Decrement</button>
    </div>
  );
};

const mapStateToProps = (state) => ({
  count: state.counter.count,
});

export default connect(mapStateToProps, { increment, decrement })(Counter);

Step 3: Use the Connected Component

You can now use the connected component in your application.

// src/App.js
import React from 'react';
import Counter from './components/Counter';

const App = () => {
  return (
    <div>
      <h1>React with Redux Example</h1>
      <Counter />
    </div>
  );
};

export default App;

Best Practices

  1. Keep Reducers Pure: Ensure that your reducers are pure functions that do not mutate the state or perform side effects.
  2. Use Action Creators: Use action creators to encapsulate the creation of action objects, making your code more readable and maintainable.
  3. Organize Your Code: Keep your actions, reducers, and components organized in separate files for better maintainability.
  4. Use Redux DevTools: Utilize Redux DevTools for debugging and inspecting state changes.

Conclusion

In this tutorial, we have covered the basics of integrating React with Redux. We set up a Redux store, created reducers, connected components to the store, and used action creators. By following these steps and best practices, you can effectively manage the state of your React application using Redux.


PreviousMiddleware in ReduxNext Handling Async Actions with Redux Thunk

Recommended Gear

Middleware in ReduxHandling Async Actions with Redux Thunk