React and React Redux — Connecting to Redux

React and React Redux — Connecting to Redux

Redux is a light weighted State Management Tool that helps the components in our React App to communicate with each other. The simple concept behind this is that every state of the component is kept in a store that will be global. So that every component can access any state from that store.

Redux is a light weighted State Management Tool that helps the components in our React App to communicate with each other. The simple concept behind this is that every state of the component is kept in a store that will be global. So that every component can access any state from that store.

Image for post

Cover Image

In this blog, let’s see a simple example of React-Redux. The logic is to increment and decrement a number on a button click with React-Redux.


Table of Contents


1. Creating React App and Initial Setup

Initially, let’s create a new React App. Also, check if everything is fine with the created project.

npx create-react-app reactapp
cd reactapp

Now let’s install Redux.

npm install redux
npm install react-redux
npm start

Now open http://localhost:3000/ and check if the server starts well. Now let’s create our views.

2. Designing Our View

Here, I am creating a simple React Class Component named Counter.jswith two buttons and a text where one button is for incrementing and the other is for decrementing. The incremented and decremented values will be displayed in the paragraph tag.

src/Counter.js

import React, { Component } from 'react'

export default class Counter extends Component {
render() {
  return ( 
      <div>
          <h1>Counter</h1>

          <button style={{ height: '40px', width: '150px' }}>Increment + </button>

          <p>4</p>

          <button style={{ height: '40px', width: '150px' }}>Decrement - </button>
      </div>
    )
  }
}

After creating the Counter view, I am including the Counter component in my App.js file.

src/App.js

import React from 'react';
import logo from './logo.svg';
import './App.css';
import Counter from './Counter'
function App() {
  return (
    <div className="App">
      <Counter />
    </div>
  );
}
export default App;

Now open your browser and navigate to http://localhost:3000/. You must see something like this.

Image for post

react-redux react redux reducer javascript

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

How native is React Native? | React Native vs Native App Development

Article covers: How native is react native?, React Native vs (Ionic, Cordova), Similarities and difference between React Native and Native App Development.

Reduce Redux Boilerplate Code with Redux-Actions

In this article, we will look at how to reduce the boilerplate code brought about by Actions and Reducers using Redux-Actions

React Native Redux | How To Use Redux In React Native

React Native Redux Example Tutorial From Scratch. We connect the React Native app to Redux store to save and retrieve the application data.

A Quick Introduction to Redux

Redux is a light weighted State Management Tool that helps the components in our React App to communicate with each other. The simple concept behind this is that every state of the component is kept in a store that will be global. So that every component can access any state from that store.

Accessing Redux from Components In React & React Native

How to set up a basic version of Redux in your React or React Native application. To make things clearer, I based my setup on my event application, where users create events that other users attend. We generated the action creators, reducers, and Redux store, and wrapped the application in a provider.