Close Menu
Soshace Digital Blog

    Subscribe to Updates

    Get The Latest News, Updates, And Amazing Offers

    What's Hot
    Recruitment

    Enhancing Recruitment: The Crucial Role of Diversity and Inclusion

    Programming

    React vs. Angular: Choosing The Right Tools for Your Next Project

    Programming

    Your New Project on Angular

    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
    Thursday, September 11
    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 13 Part 2: Asynchronous actions
    JavaScript

    React Lesson 13 Part 2: Asynchronous actions

    Mohammad Shad MirzaBy Mohammad Shad MirzaJuly 6, 2020Updated:July 29, 2020No Comments3 Mins Read
    Facebook Twitter Pinterest Telegram LinkedIn Tumblr Email Reddit
    React Lesson 13 Part 2: Asynchronous actions
    Share
    Facebook Twitter LinkedIn Pinterest Email Copy Link
    React Lesson 13 Part 2: Asynchronous actions
    React Lesson 13 Part 2: Asynchronous actions

    Hey everyone. In the previous article, we used Redux Thunk and learned how to structure actions for asynchronous calls. Now we will update reducer to handle them and then dispatch them from Articles.js. Let’s update the reducer first.

    We are not getting articles from fixtures.js now. That means we will initially have an empty array in articles instead of normalizedArticles and defaultArticles will look something like this:

    const defaultArticles = recordsFromArray(Article, []);

    Now update the initial state:

    const defaultState = new Map({
        isFetching: false,
        errors: new [],
        entities: defaultArticles,
    });

    Having the articles added here, we receive a structure that can be reused from one reducer to another, which means entities will contain articles and comments. Our code below will also be changed:

    export default (state = defaultState, action) => {
        const { type, payload, response, randomId } = action;
        switch (type) {
            case ADD_COMMENT:
          return {
            ...state, entities: state.entities.updateIn(
              [action.payload.articleId, "comments"],
              comments => comments.concat(action.randomId)
            )};
        case DELETE_ARTICLE:
          return { ...state, entities: state.entities.delete(action.payload) };
    
        //Add the three cases below
        case FETCH_ARTICLE_REQUEST:
            return { ...state, isFetching: true };
        case FETCH_ARTICLE_FAILURE:
            return { ...state, isFetching: false, errors: state.errors.push(action.error) };
        case FETCH_ARTICLE_SUCCESS:
            return { ...state, isFetching: false, entities: recordsFromArray(Article, action.payload) };
        }
        return state
    }

    As you can see, we have slightly updated our INITIAL_STATE which means we have to update the containers where we are consuming this state. Let’s start with Filters.js:

    //just update mapStateToProps
    
    const mapStateToProps = state => {
      return {
        articles: state.article.entities.valueSeq(),
        filters: state.filters
      };
    };

    Now update containers/Articles.js. We are going to call action where we are fetching all the articles from the API and update state to get those articles from entities:

    / add import
    import { fetchArticleRequest } from '../actions';
    
    //update component
    class Articles extends React.Component {
      componentDidMount(){
        this.props.fetchArticleRequest();
      }
    
      render(){
        const { articles, isFetching } = this.props;
        if(isFetching) return <p>Loading...</p>;
        return <ArticleList articles={articles} />;
      }
    }
    
    //update mapStateToProps
    const mapStateToProps = state => {
      return {
        isFetching: state.article.isFetching,
        articles: filterArticles(state.article.entities, state.filters)
      };
    };
    
    export default connect(
      mapStateToProps,
      { fetchArticleRequest } //connect action to store
    )(Articles);

    In the render function, we are checking isFetching flag which we defined earlier. While isFetching is true, we know the request is in process and we can show a loading text or spinner while we get our data. Once we have the data isFetching will be updated to false and render function will render the ArticleList on screen.

    Read More:  Conducting Effective Post-Project Evaluations: A Guide

    That’s it. We have successfully connected actions with reducer and can fetch articles from the API. I hope you understood how to use thunk for asynchronous calls in actions. Go ahead and check it. Lesson code can be found in the GitHub repo.

     

    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
    Programming October 28, 2016

    21. Node.js Lessons. Writable Response Stream (res), Pipe Method. Pt.2

    Upon the file ending you will see the end event, in the handler of which we will end our response by calling res.end. Thus, the outgoing connection will be closed for the file has been completely sent. The resulting code is quite versatile:

    Strategic Approaches to the ‘Why Should We Hire You?’ Query

    December 9, 2024

    Outdated MVP

    November 3, 2016

    Автоматическое добавление в задачи ссылок на коммиты

    June 25, 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

    14. Уроки Node.js. Отладка скриптов. Часть 2.

    Programming September 29, 2016

    This Is How I Created a Simple App Using React Routing

    JavaScript February 19, 2020

    Transforming Software Development: The Strategic Impact of Microservices

    Development December 7, 2024

    Unsupervised Sentiment Analysis using VADER and Flair

    Machine Learning April 15, 2023

    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
    JavaScript

    Build Real-World React Native App #9 : Implementing Remove Ads Feature

    Programming

    Happy Programmer’s Day!

    JavaScript

    A Complete reference guide to Redux: State of the art state management

    Most Popular

    Effective Strategies for B2B Lead Generation with Paid Ads

    B2B Leads

    Strategies for Effectively Managing Software Project Deadlines

    Development

    Building a Telegram Bot with Node.js

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

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