Close Menu
Soshace Digital Blog

    Subscribe to Updates

    Get The Latest News, Updates, And Amazing Offers

    What's Hot
    Tips

    Why Localize: Website Translation Best Practices

    Programming

    The Impact of Integrated Development Environments on Programming

    Programming

    Уроки React. Урок 12.

    Important Pages:
    • Home
    • About
    • Services
    • Contact Us
    • Privacy Policy
    • Terms & Conditions
    Facebook X (Twitter) Instagram LinkedIn YouTube
    Today's Picks:
    • Scaling Success: Monitoring Indexation of Programmatic SEO Content
    • Leveraging Influencers: Key Drivers in New Product Launches
    • How Privacy-First Marketing Will Transform the Industry Landscape
    • The Impact of Social Proof on Thought Leadership Marketing
    • Balancing Value-Driven Content and Promotional Messaging Strategies
    • Top Influencer Marketing Platforms to Explore in 2025
    • Emerging Trends in Marketing Automation and AI Tools for 2023
    • Strategies to Mitigate Duplicate Content in Programmatic SEO
    Wednesday, September 10
    Facebook X (Twitter) Instagram LinkedIn YouTube
    Soshace Digital Blog
    • Home
    • About
    • Services
    • Contact Us
    • Privacy Policy
    • Terms & Conditions
    Services
    • SaaS & Tech

      Maximizing Efficiency: How SaaS Lowers IT Infrastructure Costs

      August 27, 2025

      Navigating Tomorrow: Innovations Shaping the Future of SaaS

      August 27, 2025

      Maximizing Impact: Strategies for SaaS & Technology Marketing

      August 27, 2025
    • AI & Automation

      Enhancing Customer Feedback Analysis Through AI Innovations

      August 27, 2025

      Navigating the Impact of AI on SEO and Search Rankings

      August 27, 2025

      5 Automation Hacks Every Home Service Business Needs to Know

      May 3, 2025
    • Finance & Fintech

      Critical Missteps in Finance Marketing: What to Avoid

      August 27, 2025

      Analyzing Future Fintech Marketing Trends: Insights Ahead

      August 27, 2025

      Navigating the Complex Landscape of Finance and Fintech Marketing

      August 27, 2025
    • Legal & Compliance

      Exploring Thought Leadership’s Impact on Legal Marketing

      August 27, 2025

      Maximizing LinkedIn: Strategies for Legal and Compliance Marketing

      August 27, 2025

      Why Transparency Matters in Legal Advertising Practices

      August 27, 2025
    • Medical Marketing

      Enhancing Online Reputation Management in Hospitals: A Guide

      August 27, 2025

      Analyzing Emerging Trends in Health and Medical Marketing

      August 27, 2025

      Exploring Innovative Content Ideas for Wellness Blogs and Clinics

      August 27, 2025
    • E-commerce & Retail

      Strategic Seasonal Campaign Concepts for Online and Retail Markets

      August 27, 2025

      Emerging Trends in E-commerce and Retail Marketing Strategies

      August 27, 2025

      Maximizing Revenue: The Advantages of Affiliate Marketing for E-Commerce

      August 27, 2025
    • Influencer & Community

      Leveraging Influencers: Key Drivers in New Product Launches

      August 27, 2025

      Top Influencer Marketing Platforms to Explore in 2025

      August 27, 2025

      Key Strategies for Successful Influencer Partnership Negotiations

      August 27, 2025
    • Content & Leadership

      The Impact of Social Proof on Thought Leadership Marketing

      August 27, 2025

      Balancing Value-Driven Content and Promotional Messaging Strategies

      August 27, 2025

      Analyzing Storytelling’s Impact on Content Marketing Effectiveness

      August 27, 2025
    • SEO & Analytics

      Scaling Success: Monitoring Indexation of Programmatic SEO Content

      August 27, 2025

      Strategies to Mitigate Duplicate Content in Programmatic SEO

      August 27, 2025

      Effective Data Visualization Techniques for SEO Reporting

      August 27, 2025
    • Marketing Trends

      How Privacy-First Marketing Will Transform the Industry Landscape

      August 27, 2025

      Emerging Trends in Marketing Automation and AI Tools for 2023

      August 27, 2025

      Maximizing ROI: Key Trends in Paid Social Advertising

      August 27, 2025
    Soshace Digital Blog
    Blog / JavaScript / React / React Lessons / React Lesson 8: Deep Dive into React Redux
    JavaScript

    React Lesson 8: Deep Dive into React Redux

    Mohammad Shad MirzaBy Mohammad Shad MirzaFebruary 9, 2020Updated:February 9, 2020No Comments6 Mins Read
    Facebook Twitter Pinterest Telegram LinkedIn Tumblr Email Reddit
    React Lesson 8: Deep Dive into React Redux
    Share
    Facebook Twitter LinkedIn Pinterest Email Copy Link
    React Lessons. Lesson 8. Deep Dive into React Redux
    React Lessons. Lesson 8. Deep Dive into React Redux

    In the previous lesson, we understood the working of Redux by building a Counter app. Now, we will apply that knowledge and go in-depth with the React-Redux library. Let’s start.

    First, we will make some changes to our folder structure. The components including Provider are called container that contains store. Let’s create a new folder “containers” and add a root container.

    ///containers/Root.js
    import React from "react";
    import Articles from "./Articles";
    import Counter from "./Counter";
    import { Provider } from "react-redux";
    import store from "../store";
    
    function Root() {
      return (
        <Provider store={store}>
          {/* <Counter /> */}
          <Articles />
        </Provider>
      );
    }
    
    export default Root;

    Now, change our index file to import the root container:

    //index.js
    
    import React from "react";
    import ReactDOM from "react-dom";
    import Root from "./containers/Root"; //import Root
    
    const rootElement = document.getElementById("root");
    ReactDOM.render(<Root />, rootElement);

    That’s good enough. Let’s move on to React-Redux in our main application.

    Use Redux to serve our articles

    Redux divides objects into “containers” and “components.” “Smart” components are those connected with “Store” – such as Counter, for example. And some components simply receive data and render them. Now we’ll have two containers – Counter and ArticleList. We will add Redux with ArticleList. Let’s get a quick idea of how we’ll do it:

    1. Create a reducer to serve all the articles.
    2. Connect ArticleList to store which will render the article list.
    3. Write an action to delete any article.
    4. Dispatch the action to filter out an article from the article list.

    Let’s dive into code

    Let’s dive into code

    1. Create a reducer to serve all the articles

    We already created a “counter” reducer inside the “reducers” folder. Similarly, we will create an “articles” reducer and export it.

    //reducers/articles.js
    
    //import the article array
    import { articles as defaultArticles } from "../fixtures";
    
    //define initial state
    const INITIAL_STATE = {
      articles: defaultArticles
    };
    
    //create a basic reducer function to return state
    export default (state = INITIAL_STATE, action) => {
      switch (action.type) {
        default:
          return state;
      }
    };

    Let’s recall reducers from the previous lesson, “Reducers are just pure functions that return a new state every time we dispatch an action which in turn re-render the View.”

    Previously, we had just a single reducer “index.js” which we split into two separate reducers “articles.js” and “counter.js”. We will “combineReducers” from the “redux” library to combine and export them to the store.

    //reducers/index.js
    
    import { combineReducers } from "redux";
    import article from "./articles";
    import counter from "./counter";
    export default combineReducers({
      article,
      counter
    });

     2. Connect ArticleList to store which will render the article list.

    Components that are connected to the store are called containers. We are going to create an “Articles” component inside the “containers” folder and connect it with the store.

    //containers/Articles.js
    
    import React from "react";
    import { connect } from "react-redux";
    import ArticleList from "../components/ArticleList";
    
    function Articles(props) {
      const { articles } = props;
      return <ArticleList articles={articles} />;
    }
    
    const mapStateToProps = state => {
      return {
        articles: state.article.articles
      };
    };
    
    export default connect(
      mapStateToProps,
      {}
    )(Articles);

    We are using the “connect” function from the “react-redux” library to connect the “Articles” component with the store. As we learned in the previous lesson, connect in a Higher-Order function receives two arguments:

    • mapStateToProps
    • mapDispatchToProps
    Read More:  The Ultimate Guide to Drag and Drop Image Uploading with Pure JavaScript

    “mapStateToProps” enables us to use state from reducer inside our component. We used “articles” from the reducer state and passed it as props above. We are using actions here, so we will leave the second argument empty for now.

    3. Write an action to delete any article

    We wrote two actions “increment” and “decrement” in the previous lesson. Similarly, we will write a “deleteArticle” action to delete any article from article array. Let’s create an action type first:

    //types.js
    
    export&nbsp;const&nbsp;DELETE_ARTICLE&nbsp;=&nbsp;"delete_article";

    Action types are defined to avoid spelling mistakes while writing them inside actions and reducers. Now we will create an articles file inside actions folder:

    //actions/articles.js
    
    //import action type
    import { DELETE_ARTICLE } from "../types";
    
    //define action
    export const deleteArticle = id => {
      return {
        type: DELETE_ARTICLE,
        payload: id
      };
    };

    Let’s recall actions from the previous lesson, “Actions are a piece of code that tells how to change state”. Here, our “deleteArticle” action gets an “id” and passes it to the reducer to filter out the article with that particular “id.”

    Previously, we had only one action creator as “actions/index.js,” which we split into two separate action creators “articles.js” and “counter.js”. They can be exported as:

    export * from "./counter";
    export * from "./articles";

    The reducer will be updated like this:

    //reducers/articles.js
    
    //import type
    import { DELETE_ARTICLE } from "../types";
    import { articles as defaultArticles } from "../fixtures";
    
    const INITIAL_STATE = {
      articles: defaultArticles
    };
    
    //get id from action.payload and return the filtered state
    export default (state = INITIAL_STATE, action) => {
      switch (action.type) {
        case DELETE_ARTICLE:
          const filteredArticles = state.articles.filter(
            article => article.id !== action.payload
          );
          return { ...state, articles: filteredArticles };
    
        default:
          return state;
      }
    };

    Now, we just have to dispatch the action from a view.

    Read More:  React Lesson 6: CSS and Animation

    4. Dispatch the action to filter out an article from the article list.

    The best place to dispatch the “deleteArticle” action is when a user clicks on any article. Let’s connect the Article component which is rendering each article to store.

    /components/Article/index.js
    
    import React, { Component } from "react";
    import PropTypes from "prop-types";
    import CommentList from "../CommentList";
    import "./style.css";
    import { CSSTransition } from "react-transition-group";
    
    //import connect and action 
    import { connect } from "react-redux";
    import { deleteArticle } from "../../actions";
    
    class Article extends Component {
      static propTypes = {
        article: PropTypes.object.isRequired
      };
    
      handleDelete = event => {
        event.preventDefault();
        // get action from props
        const { article, deleteArticle } = this.props;
        deleteArticle(article.id);
      };
    
      render() {
        const {
          isOpen,
          openArticle,
          article: { title, text, comments }
        } = this.props;
        return (
          <div className="article">
            <h1 onClick={openArticle}>{title}</h1>
    
            //call deleteAction on button click
            <a href="#" onClick={this.handleDelete}>
              delete me
            </a>
            <CSSTransition
              in={isOpen}
              timeout={500}
              classNames="article"
              unmountOnExit
            >
              <section>
                {text} <CommentList comments={comments} />
              </section>
            </CSSTransition>
          </div>
        );
      }
    }
    
    //connect the article to store
    export default connect(
      null,
      { deleteArticle }
    )(Article);

    Our first argument of “connect” is null because we are not using anything from the reducer state. The second argument “mapDispatchToProps” takes actions and maps them to props. This will make sure the “deleteArticle” action is provided as a prop to the component.

    Our Article container with delete functionality is ready. You can visit this codesandbox below to see it in action.

      Edit React_lesson_lesson8

    Your home task:

    Do Reducer and a part of Store for filters, as well as create the filtering functionality for the articles. It means, in the end, upon choosing a time in the calendar, only those articles added during this time should be displayed. And transmit all these filters from ArticleList to the “filters” component. Handle these filters through Redux – so, ArticleList will display only the filtered data.

    This lesson’s coding can be found here.

    react react lesson react redux
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email
    Mohammad Shad Mirza
    • X (Twitter)
    • LinkedIn

    JavaScript lover working on React Native and committed to simplifying code for beginners. Apart from coding and blogging, I like spending my time sketching or writing with a cup of tea.

    Related Posts

    Streamlining Resource Allocation for Enhanced Project Success

    December 18, 2024

    Conducting Effective Post-Project Evaluations: A Guide

    December 16, 2024

    Strategies for Keeping Projects on Track and Meeting Deadlines

    December 10, 2024
    Leave A Reply Cancel Reply

    You must be logged in to post a comment.

    Stay In Touch
    • Facebook
    • Twitter
    • Pinterest
    • Instagram
    • YouTube
    • Vimeo
    Don't Miss
    Beginners July 5, 2019

    5 Critical Tips for Designing Your First Website

    Tackling the challenge of designing your first website can be daunting if you’ve never done it before. Luckily, learning web design with the current state of the Internet is far more simple. I recommend you give it a try. Here are a few critical pieces of advice to get you started:

    21. Уроки Node.js. Writable Поток Ответа res, Метод pipe. Pt.2

    October 26, 2016

    Node.js Lesson 9: Events, EventEmitter and Memory Leaks

    November 2, 2020

    23. Уроки Node.js. Домены, “асинхронный try..catch”. Часть 1.

    November 14, 2016

    Categories

    • AI & Automation
    • Angular
    • ASP.NET
    • AWS
    • B2B Leads
    • Beginners
    • Blogs
    • Business Growth
    • Case Studies
    • Comics
    • Consultation
    • Content & Leadership
    • CSS
    • Development
    • Django
    • E-commerce & Retail
    • Entrepreneurs
    • Entrepreneurship
    • Events
    • Express.js
    • Facebook Ads
    • Finance & Fintech
    • Flask
    • Flutter
    • Franchising
    • Funnel Strategy
    • Git
    • GraphQL
    • Home Services Marketing
    • Influencer & Community
    • Interview
    • Java
    • Java Spring
    • JavaScript
    • Job
    • Laravel
    • Lead Generation
    • Legal & Compliance
    • LinkedIn
    • Machine Learning
    • Marketing Trends
    • Medical Marketing
    • MSP Lead Generation
    • MSP Marketing
    • NestJS
    • Next.js
    • Node.js
    • Node.js Lessons
    • Paid Advertising
    • PHP
    • Podcasts
    • POS Tutorial
    • Programming
    • Programming
    • Python
    • React
    • React Lessons
    • React Native
    • React Native Lessons
    • Recruitment
    • Remote Job
    • SaaS & Tech
    • SEO & Analytics
    • Soshace
    • Startups
    • Swarm Intelligence
    • Tips
    • Trends
    • Vue
    • Wiki
    • WordPress
    Top Posts

    How to use the redux dev tools to speed up development and debugging

    React December 24, 2020

    23. Уроки Node.js. Домены, “асинхронный try..catch”. Часть 2.

    Programming November 16, 2016

    Maximizing ROI: Key Trends in Paid Social Advertising

    Marketing Trends August 27, 2025

    Learn JavaScript and React with the TOP JavaScript YouTube Channels

    JavaScript May 16, 2019

    Subscribe to Updates

    Get The Latest News, Updates, And Amazing Offers

    About Us
    About Us

    Soshace Digital delivers comprehensive web design and development solutions tailored to your business objectives. Your website will be meticulously designed and developed by our team of seasoned professionals, who combine creative expertise with technical excellence to transform your vision into a high-impact, user-centric digital experience that elevates your brand and drives measurable results.

    7901 4th St N, Suite 28690
    Saint Petersburg, FL 33702-4305
    Phone: 1(877)SOSHACE

    Facebook X (Twitter) Instagram Pinterest YouTube LinkedIn
    Our Picks
    Tips

    UX Engineers and the Skills They Need

    Programming

    Уроки React. Урок 13. Часть 2.

    Beginners

    Data Science Overview: The Bigger Picture

    Most Popular

    How We are Looking for Proposals on UpWork

    Remote Job

    Unlocking Organizational Growth: The Crucial Role of Recruitment

    Recruitment

    Уроки React. Урок 3

    Programming
    © 2025 Soshace Digital.
    • Home
    • About
    • Services
    • Contact Us
    • Privacy Policy
    • Terms & Conditions

    Type above and press Enter to search. Press Esc to cancel.