Should I initiate a new dispatch or is there another reason why my code isn't executing?

I'm currently working on implementing a functionality where my preload shows up during an AJAX request and disappears once the request is completed, regardless of success or failure.

Utilizing Axios, I've explored their interceptors for managing both requests and responses. At the moment, my focus is on handling the request aspect.

import axios from "axios";
import {setPreLoader} from './PreLoaderActions.js';

export const axiosInstant = axios.create({
    baseURL: 'http://localhost:54690/api',
    timeout: 2000,
});

export const config = axiosInstant.interceptors.request.use( config => {
    // Perform actions before sending the request
    console.log('afaf');
    setPreLoader(true);
    return config;
  }, function (error) {
    // Handle request error
   // this.setPreLoader(false);
    return Promise.reject(error);
  });


import {actions} from './Actions.js';

export function setPreLoader(show) {
     return function (dispatch) {
        dispatch({ type: actions.SHOW_PRE_LOADER, payload: { showPreLoader: show } });
    };
}

Upon triggering setPreloader(true), no action seems to be triggered. There is no dispatch occurring, which is puzzling. I wonder if there's another step required, considering I've only employed this within a React component previously, so Redux/ReactJS might be handling some aspects automatically.

Answer №1

The activateLoader method simply returns an anonymous function without performing any actions on its own. So, invoking activateLoader(true) by itself will not have any effect since the anonymous function is not executed.

To trigger the behavior, you need to execute the returned anonymous function with a suitable function as follows:

activateLoader(true)(executeFunction)

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Rather than overwriting it, append a new value to the localstorage

I am trying to insert the value of newUsername into the localStorage setUsernamesArray. However, my current code overwrites the existing value instead of adding to it. Code $('#signUpButton').click(function() { var newUsername = $('#userna ...

Tips for activating a function when the sidebar menu is opened in Ionic 2

How can I trigger a function when the SideMenu is open in Ionic 2? I came across this link here for Ionic-1, but I'm wondering how to accomplish this in Ionic 2. Any help would be appreciated. Thanks! ...

Tips for showing JSON data within multiple <div> elements on an HTML page with AngularJS and ng-repeat

I am looking to display JSON values on my HTML page, each in a separate div based on the image URL value from the .json file. However, I am encountering difficulties in displaying these values in the divs. Can someone please guide me on how to iterate and ...

Guide on looping through deeply nested children within an object to accumulate a list of names

Within an object, there are numerous parent and child elements var obj={ name: 'one', child:{ name: 'two', child:{ name: 'three', child.. } } } foo(obj) Create a ...

Dynamically populate the dropdown options in Angular as the dropdown is selected during runtime

I have a JSON object that holds the names of different dropdowns. It looks something like this - $scope.dropdowns = { "dp1" :{}, "dp2" :{} } The objects dp1 and dp2 correspond to their respective dropdown menus. These objects will be used by th ...

Assign a zip code to a form for visitors and clients in the WooCommerce platform

The primary purpose is to validate a visitor's postcode and display various messages based on it. I referred to this thread for setting the shipping code: Set shipping postcode early before add to cart in WooCommerce I have successfully created an AJ ...

I am eager to create a Material-UI textfield using an array

My current task involves utilizing TextField based on an Array, but I am facing an issue with dynamically changing all the values. I understand that I can employ ternary conditions to accomplish this task effectively. const TextField = () => { r ...

Having trouble performing a basic $lookup operation on two collections' ObjectIds in Mongo DB

Currently, I am delving into the world of Mongo DB Atlas using node.js and oboe to stream results to HTML. As a newcomer to these technologies, I would greatly appreciate explanations in simpler terms. My objective is to perform a $lookup operation betwee ...

Get tabular information in xlsx format by utilizing the xlsx npm package for download

I have been attempting to convert my json-like data into an xlsx file format. I utilized the xlsx npm package and followed various code samples available online, however, when trying to open the file in Excel, I encountered the following error: https://i.s ...

Prevent browser menus from opening by using JavaScript without triggering a new popup window

In seeking to safeguard the source code of my website, I am looking to prevent any unauthorized access. Therefore, I aim to deactivate all common methods of accessing the code such as Ctrl+U, Ctrl+Shift+I, F12, and browser menu options. ...

The ASP Ajax Calendar Extender and time presentation

I have been working with the Ajax Control Toolkit Calendar Extender control and I am facing an issue. I need to display both the date and time in some fields, but when I set the Format to "dd/MM/yyyy hh:mm:ss", the time section is not displayed correctly. ...

Unexpected behavior in ReactJS when using Material UI

In my Webpack + ReactJS project, I am working on creating a table using Material UI. I am trying to implement an 'icon menu' feature with a 'menu item' that allows users to delete a specific line along with its associated data. Below i ...

Combine React 17 with webpack 5 and babel-plugin-react-css-modules, enabling the use of CSS modules with stylename functionality

I am in the process of setting up a new React application using the latest technologies available, including React 17, Webpack 5, and other essential modules. My goal is to implement CSS modules utilizing the styleName concept with the help of babel-plugi ...

Receiving an unspecified reply after making an ajax request

I am experiencing difficulties with retrieving the results from an ajax call. When I use console.log(data) to log the data, it is showing [undefined]. Here is the code snippet for the ajax call: $.get(root+'hotels/functions/ean/get-zones.php', { ...

Toggle visibility of an Angular 4 component based on the current route

Hello there, I'm facing an issue and not sure if it's possible to resolve. Essentially, I am looking to display a component only when the route matches a certain condition, and hide another component when the route matches a different condition. ...

Retrieve information from an API and assign the corresponding data points to the graph using Material UI and React

I have 4 different APIs that I need to interact with in order to fetch specific details and visualize them on a bar graph. The data should be organized based on the name, where the x-axis represents the names and the y-axis represents the details (with 4 b ...

Using Jquery to Redirect Users According to URL Position

My current dilemma involves... I want to create a condition where if the URL specifically contains /foldername/index.htm or /foldername/ on mydomain.com, then it should redirect to http://www.example.com If the URL includes any URL parameter with /folder ...

Issue: React error message indicates that the .map() function is not recognized. The API response is in the form of an object, making

As a newcomer to REACT.JS, I am currently facing the challenge of extracting data from an API for my project. Utilizing "Axios" for sending the get request, I have encountered a situation where the response comes back as an array in one API and as an objec ...

Is there a way to use fetch() to automatically redirect a user after logging in?

I'm currently working on a node.js application using express, and I am in the process of creating a login form for my users. I want to include a Javascript file that utilizes fetch() to send a POST request to my API for user authentication. However, I ...

Add the "multiple" attribute to ui-select only if certain conditions are met

I am attempting to dynamically add the multiple attribute to a ui-select directive based on the value of a specific property by using the ng-attr- directive. Unfortunately, this method is not functioning as expected in my case. To better illustrate the iss ...