Close Menu
Soshace Digital Blog

    Subscribe to Updates

    Get The Latest News, Updates, And Amazing Offers

    What's Hot
    React

    Build Real-World React Native App #8 : implement Dark mode

    Development

    Ensuring Quality: The Critical Role of Testing in Software Development

    Tips

    7 Best App Makers to Build Your Own Mobile App

    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
    Sunday, September 28
    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:  Create simple POS with React, Node and MongoDB #2: Auth state, Logout, Update Profile

    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
    Entrepreneurship December 16, 2024

    Crafting a High-Performing Team: A Startup’s Essential Guide

    Creating a high-performing team is crucial for startup success. Focus on diverse skill sets, foster open communication, and establish clear goals. Invest in continuous learning and empower individuals to take ownership, driving innovation and collaboration forward.

    Last Chance to Get Your Running Remote Early-Bird Ticket!

    November 18, 2019

    Yarn vs. npm in 2019: Choosing the Right Package Manager for the Job

    June 11, 2019

    How to Take Control of Your Tech Interview | Take Charge in Three Easy Steps

    March 22, 2019

    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 Secure Python Web App Using Bandit

    Programming February 13, 2021

    Building a Simple CLI Youtube Video Downloader in NodeJS

    JavaScript March 4, 2020

    Работа с заказчиком

    Wiki December 31, 2015

    Strategies for Identifying Quality LinkedIn Prospects by Niche

    LinkedIn December 7, 2024

    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

    Introduction to the Best Code Playgrounds: JSFiddle, Codepen, and CodeSandbox

    Beginners

    Technical Writing: Practical & Theoretical Advice

    Programming

    Доклад. Agile (вводная часть). Scrum

    Most Popular

    An Introduction to Finite State Machines: Simplifying React State Management with State Machines

    JavaScript

    Strategies for Identifying High-Quality LinkedIn Prospects by Niche

    LinkedIn

    Interview with Alexander

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

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