React App Slow Due to Large API Response: How to Improve Performance?

I’m working on a React app where I fetch flight offers using the Amadeus API. My form allows users to input flight details (from, to, departure date, return date), and upon submission, I fetch the flight offers and display them.

The problem is that after fetching the API data, which returns a large response, my app becomes sluggish. Form inputs, buttons, and onChange handlers experience noticeable delays when interacting with the UI.

Here is a simplified version of my code:

I fetch data successfully, but the large amount of data makes the rest of the app (including form handling) slow and unresponsive.

const [formData1, setFormData1] = useState({
    from_inp: '',
    to_inp: '',
    depart_inp: '',
    return_inp: '',
});

const handleSubmit = async (e) => {
  e.preventDefault();
  try {
    const fromIATA = formData1.from_inp.split('(')[1].replace(')', '');
    const toIATA = formData1.to_inp.split('(')[1].replace(')', '');

    const params = {
      originLocationCode: fromIATA,
      destinationLocationCode: toIATA,
      departureDate: formData1.depart_inp,
      adults: 1,
      children: 1,
    };

    if (formData1.return_inp) {
      params.returnDate = formData1.return_inp;
    }

    // Fetch access token
    const tokenResponse = await axios.post('https://test.api.amadeus.com/v1/security/oauth2/token', {
      grant_type: 'client_credentials',
      client_id: 'YOUR_CLIENT_ID',
      client_secret: 'YOUR_CLIENT_SECRET',
    });

    const accessToken = tokenResponse.data.access_token;

    // Fetch flight offers
    const response = await axios.get('https://test.api.amadeus.com/v2/shopping/flight-offers', {
      params: params,
      headers: {
        'Authorization': `Bearer ${accessToken}`,
      },
    });

    const apiResponse = response.data;
    console.log('API Response:', apiResponse);

    // Handle flight details
    if (Array.isArray(apiResponse.data)) {
      setFlightDetails(apiResponse.data);
    } else {
      setError('No flight details match your search.');
      setFlightDetails([]);
    }

  } catch (error) {
    console.error('Error fetching flight offers:', error);
    setError(`Error fetching flight details: ${error.message}`);
    setFlightDetails([]);
  }
};

What I’ve Tried:

I use useState to handle form inputs.

I considered debouncing onChange handlers but it hasn’t fully resolved the issue.

I’m considering limiting API results, but I want the app to remain responsive even when large amounts of data are fetched.

My Questions:

How can I optimize my app so that form submissions and button clicks don’t lag when handling large API responses?

Should I paginate the API data, or is there a more effective way to handle large responses?

Are there any React-specific techniques I can apply to improve UI performance?

Any advice on how to resolve the performance issues would be greatly appreciated!

New contributor

Rushabh Dhamne is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

1

I think you should apply pagination or you can also apply Lazy loading for Improved Performance, Lower Memory Usage, and Reduced Resource Consumption.
Lazy loading components is particularly beneficial when dealing with large API responses.

New contributor

Rao Sarim Ali is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Look up “list virtualization”, and you will find a bunch of articles about how to optimize the rendering of large lists by keeping most of the items in a virtual state and displaying only the ones visible on the screen. I think it might be one way to fix your issue.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật