J José Leiva

Improving UX: Implementing Global Loading States in Proyecto-FinanzApp.io

Users hate staring at a frozen screen while waiting for an API response. In Proyecto-FinanzApp.io, we recently addressed this friction by introducing a unified loading indicator for all critical data operations, including authentication and CRUD actions.

The Problem: The 'Silent Wait'

Previously, our application relied on background requests via Axios without immediate visual feedback. When a user clicked to save a transaction or authenticate via JWT, the UI remained static until the promise resolved. This led to 'double-clicks' and user anxiety regarding whether their action was processed.

The Solution: Global State Management

To solve this, we implemented a centralized loading state pattern using React hooks. By wrapping our API service layer, we can toggle a global boolean flag whenever an HTTP request is in progress.

import axios from 'axios';
import { useState } from 'react';

export const useApi = () => {
  const [isLoading, setIsLoading] = useState(false);

  const request = async (config) => {
    setIsLoading(true);
    try {
      return await axios(config);
    } finally {
      setIsLoading(false);
    }
  };

  return { isLoading, request };
};

This simple wrapper ensures that any component utilizing our custom hook automatically benefits from loading status awareness.

Implementation Impact

By tying our UI components to this global state, we were able to:

  1. Disable inputs during pending requests to prevent duplicate submissions.
  2. Display spinners automatically when the API is active.
  3. Improve perceived performance by acknowledging user intent immediately.

The Takeaway

UX is not just about the final data rendered on the screen; it's about the communication between the system and the user during the transition. Small additions, like a global loading indicator, drastically reduce user frustration and prevent data inconsistencies caused by repeated clicks.


Generated with Gitvlg.com

Improving UX: Implementing Global Loading States in Proyecto-FinanzApp.io
J

José Leiva Campos

Author

Share: