Reusable React hook vs complex javascript response structure

I’m writing a web application using React.
In my code I have plenty different calls to the database.
All of this calls look very similar.
The only difference are table names and parameters and therefore I have a lot of functions that fetch the data.

For this reason I figured that I will write a generic hook that will take care of all my API calls.

The hook looks like this:

"use client"

import { useState, useEffect } from 'react';

export function useAWSGenericRequest(fetch_callback) {
    const [value, setValue] = useState({
      status: "pending",
      value: []
    });


    useEffect(() => {
      fetch_callback().then(function(request) {
        request.on("success", function(response){
          setValue(function() {
            return {
              status: "success",
              value: response}
          });
        });
        request.send();
      });
      }, []);
    return { value: value, setValue: setValue };
}

Then in the code I use it like this:

import { FetchUsers } from '@/app/lib/fetch-users.js';
import { useAWSGenericRequest } from '@/app/ui/hooks/use-aws-generic-request.js'
.
.
.
export default function ListOfUsers(props) {
    const users = useAWSGenericRequest(FetchUsers);
.
.
.
    return (users.value.value.data.Users.map(function(user, i) 
        => return (<div key={i}>{user.email}</div>)));

}

This code is simplified but it portrays the problem that I have.
The nested structure of my API response “users.value.value.data.Users” causes my user interface to be no longer responsive once the “users.value.value.data.Users” changes.
I read on the internet that react will not react on the nested array changes.

One solution would be to modify the generic hook that I mentioned earlier and make it look like this:

"use client"

import { useState, useEffect } from 'react';

export function useAWSGenericRequest(fetch_callback) {
    const [value, setValue] = useState([]);


    useEffect(() => {
      fetch_callback().then(function(request) {
        request.on("success", function(response){
          setValue(function() {
            return response.value.data.Users);
        });
        request.send();
      });
      }, []);
    return [value, setValue];
}

Then in the code I could use it like this:

import { FetchUsers } from '@/app/lib/fetch-users.js';
import { useAWSGenericRequest } from '@/app/ui/hooks/use-aws-generic-request.js'
.
.
.
export default function ListOfUsers(props) {
    const [users, setUsers] = useHandleGetSupplementById(supplement_id);
.
.
.
    return (users.map(function(user, i) 
        => return (<div key={i}>{user.email}</div>)));

}

In this case React does react and reloads the user interface every time I change the “users” array.

The problem obviously is that If I wanted to fetch some other value then I would need to copy my hook and replace the dotted path to get the resource I’m interested in like in this example response.value.some.other.value:

"use client"

import { useState, useEffect } from 'react';

export function useAWSGenericRequest(fetch_callback) {
    const [value, setValue] = useState([]);


    useEffect(() => {
      fetch_callback().then(function(request) {
        request.on("success", function(response){
          setValue(function() {
            return response.value.some.other.value);
        });
        request.send();
      });
      }, []);
    return [value, setValue];
}

I feel like I’m missing some very simple trick/pattern but I just don’t know what it is.
Is there a way to create a generic hook like I’m trying to or do I need to accept the fact that I have create new hook for each new API call?

Best Regards

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