Home Projects Portfolio Dashboard Export PDF Log in
React Axios

Optimizing Medical Appointment Views in React

The Challenge

In our front2_examen_final_pweb project, the medical appointment module was displaying the entire list of available shifts regardless of which doctor was selected by the user. This led to a cluttered interface and an inefficient user experience, forcing users to manually search for appointments specific to their chosen physician.

The Implementation

To address this, we implemented a filtered state management approach using React. By capturing the selection event and passing the doctor's identifier to our API request, we ensure that the UI only reflects relevant data.

const fetchAvailableSlots = async (doctorId) => {
  try {
    const response = await axios.get(`/api/doctors/${doctorId}/appointments`);
    setAppointments(response.data);
  } catch (error) {
    console.error("Failed to load slots", error);
  }
};

This function triggers an Axios request to a specific endpoint that returns only the appointments associated with the provided doctorId. By updating the appointments state only with the returned data, we keep the view clean and responsive.

Key Decisions

  1. Server-side Filtering: Offloading the search to the backend ensures the frontend doesn't need to process large arrays of data.
  2. Conditional Rendering: The React component remains reactive, automatically refreshing the list whenever the doctorId state changes.
  3. Asynchronous Requests: Using Axios handles the network lifecycle cleanly, allowing us to manage loading and error states during the fetch operation.

Results

  • Improved application performance by reducing the payload size.
  • Enhanced user experience by providing a filtered and relevant view immediately upon doctor selection.
  • Cleaner codebase by decoupling the selection logic from the global data store.

Lessons Learned

Filtering data at the source—the API—is always more efficient than filtering it on the client side. When building search-heavy features, move the filtering logic as close to the database as possible.

Takeaway: Next time you have a selection-based UI, ensure your API endpoints accept parameters for filtering to minimize network overhead and improve interface clarity.


Generated with Gitvlg.com

Optimizing Medical Appointment Views in React
Zelaya Noelia

Zelaya Noelia

Author

Share: