react redux counter example

React Redux Counter Example: Step-by-Step Tutorial

By Emily Moore
AD

React and Redux are two fundamental tools in modern web development, often used in tandem to manage state effectively in JavaScript applications. A common example of their combined use is creating a simple counter application. In this article, we'll guide you through building a React-Redux counter example, explaining key concepts and best practices along the way.

Let's begins by understanding the key components of this project: React for the view layer, Redux for state management, and React-Redux for binding these two libraries together.

Setting Up the Project

To start, install the necessary dependencies: React, Redux, and React-Redux.

AD
React projet setup
React projet setup
React Context API vs Redux: When and How to Use Each – Djamware
React Context API vs Redux: When and How to Use Each – Djamware
Efficient State Management in React with Redux and React Hooks
Efficient State Management in React with Redux and React Hooks

First, initialize your project with npm or yarn. Then, navigate to your project directory and run `npm install react react-dom redux react-redux`.

Project Structure

Creating a simple folder structure for your project is essential. Here's a basic structure to follow:

20 REACT HOOKS EVERY DEVELOPER SHOULD KNOW
20 REACT HOOKS EVERY DEVELOPER SHOULD KNOW
react server components are connected to each other with the same symbol in front of them
react server components are connected to each other with the same symbol in front of them
React Redux Full Course for Beginners | Redux Toolkit Complete Tutorial
React Redux Full Course for Beginners | Redux Toolkit Complete Tutorial
  • src: This is where your application's code resides.
  • src/actions: Redux actions go here.
  • src/reducers: Redux reducers go here.
  • src/components: React components go here.
  • App.js: The main application component.
  • index.js: The entry point of your application.

Creating the Store

After setting up the project structure, let's create a Redux store. In your main `index.js` file, include the following code:

import { createStore } from 'redux';

AD

import rootReducer from './reducers';

10 REACT PROJECTS EVERY FRONTEND DEVELOPER SHOULD BUILD
10 REACT PROJECTS EVERY FRONTEND DEVELOPER SHOULD BUILD
Redux tutorial for beginners
Redux tutorial for beginners
React With Redux Tutorial | React Redux Tutorial For Beginners | ReactJS For Beginners | Simp...
React With Redux Tutorial | React Redux Tutorial For Beginners | ReactJS For Beginners | Simp...
React Fundamental
React Fundamental
React – The Complete Guide | Learn React, Next.js & Redux
React – The Complete Guide | Learn React, Next.js & Redux
React Component Lifecycle — Complete Visual Guide (Class + Hooks)
React Component Lifecycle — Complete Visual Guide (Class + Hooks)

const store = createStore(rootReducer);

ReactDOM.render(, document.getElementById('root'), {store});

AD

Creating Redux Actions

Now, let's create actions that will update our counter. In `src/actions/index.js`, include the following:

the user's guide to implement notifications in reactt, including icons and text
the user's guide to implement notifications in reactt, including icons and text
30 REACT INTERVIEW QUESTIONS EVERY DEVELOPER SHOULD PRACTICE
30 REACT INTERVIEW QUESTIONS EVERY DEVELOPER SHOULD PRACTICE
a poster with different types of people and words on it that say react in short
a poster with different types of people and words on it that say react in short
two blue and black logos, one with an atomic symbol on it's side
two blue and black logos, one with an atomic symbol on it's side
React JS Cheat Sheet
React JS Cheat Sheet
NEXT.JS VS REACT (2026)
NEXT.JS VS REACT (2026)
These React Fundamentals You Skip may be Killing You
These React Fundamentals You Skip may be Killing You
State Management in React Query (2025 Guide for MERN Developers)
State Management in React Query (2025 Guide for MERN Developers)
4 React Design Patterns You Should Know
4 React Design Patterns You Should Know
The only introduction to Redux (and React-Redux) you’ll ever need
The only introduction to Redux (and React-Redux) you’ll ever need
Redux easy explanation 😎 React Redux Beginners Guide
Redux easy explanation 😎 React Redux Beginners Guide
the top 10 new updates in react 19, which are available for all users to use
the top 10 new updates in react 19, which are available for all users to use
a board game with the words react on it and an image of a maze in front of
a board game with the words react on it and an image of a maze in front of
I created the exact same app with Redux and React. Here are the differences.
I created the exact same app with Redux and React. Here are the differences.

export const INCREMENT_COUNT = 'INCREMENT_COUNT';

export const decrementCount = {type: DECREMENT_COUNT,payload: 1);

AD

export const incrementCount = {type: INCREMENT_COUNT,payload: 1);

Creating the Reducer

The reducer will handle updating the state based on the dispatched actions. In `src/reducers/index.js`, include the following:

const counterReducer = (state = 0, action) => {

switch (action.type) {

case INCREMENT_COUNT:

return state + action.payload;

case DECREMENT_COUNT:

return state - action.payload;

default:

return state;

}}

};

export default counterReducer;

Creating React Components

Let's create a simple React component for our counter. In `src/components/Counter.js`:

The Component Structure

The component structure involves a button to decrease, display the count, and another button to increase the count.

import React from 'react';

const Counter = () => (

{

const [count, setCount] = React.useState(0);

const decreaseCount = () => {

setCount(count - 1);

};

const increaseCount = () => {

setCount(count + 1);

};

return (

<div>

<button onClick={decreaseCount} -> Decrement</button>

<p>Count: {count}</p>

<button onClick={increaseCount} -> Increment</button>

</div>

);

};

export default Counter;

Connecting React and Redux

Finally, use the `connect` function from `react-redux` to connect our React component to the Redux store. In `src/components/CounterConnected.js`:

import { connect } from 'react-redux';

import Counter from './Counter';

const mapStateToProps = (state) => ({

count: state.counter

});

export default connect(mapStateToProps)(Counter);

In a simple and clean way, we've created a React-Redux counter example. The core principle is to separate the application's logic and views into different libraries and use `react-redux` to connect them. This pattern makes the application highly manageable and scalable.

Now that you've created a counter app using React and Redux, explore more complex examples and dive deeper into Redux middleware, tucked actions, and asyncredux to further enhance your understanding of Redux.

AD