@axzydev/axzy_ui_system 1.2.14 → 1.2.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -2755,36 +2755,46 @@ function ITDataTable({
2755
2755
  handleItemsPerPageChange
2756
2756
  } = useTableState({ defaultItemsPerPage });
2757
2757
  const debounceTimerRef = (0, import_react11.useRef)(null);
2758
+ const hasFetchedRef = (0, import_react11.useRef)(false);
2759
+ const fetchDataRef = (0, import_react11.useRef)(fetchData);
2760
+ fetchDataRef.current = fetchData;
2761
+ const externalFiltersRef = (0, import_react11.useRef)(externalFilters);
2762
+ externalFiltersRef.current = externalFilters;
2763
+ const externalKey = JSON.stringify(externalFilters);
2758
2764
  const computedTotalPages = Math.ceil(totalItems / itemsPerPage) || 1;
2759
2765
  const performFetch = (0, import_react11.useCallback)(async () => {
2760
2766
  setIsLoading(true);
2761
2767
  try {
2762
- const response = await fetchData({
2768
+ const response = await fetchDataRef.current({
2763
2769
  page: currentPage,
2764
2770
  limit: itemsPerPage,
2765
- filters: { ...filters, ...externalFilters },
2771
+ filters: { ...filters, ...externalFiltersRef.current },
2766
2772
  sort: sortConfig || void 0
2767
2773
  });
2768
2774
  setData(response.data || []);
2769
2775
  setTotalItems(response.total || 0);
2776
+ hasFetchedRef.current = true;
2770
2777
  } catch (error) {
2771
2778
  console.error("ITDataTable: Error fetching data", error);
2772
2779
  setData([]);
2773
2780
  setTotalItems(0);
2781
+ hasFetchedRef.current = true;
2774
2782
  } finally {
2775
2783
  setIsLoading(false);
2776
2784
  }
2777
- }, [currentPage, itemsPerPage, filters, sortConfig, fetchData, externalFilters]);
2785
+ }, [currentPage, itemsPerPage, filters, sortConfig]);
2786
+ const performFetchRef = (0, import_react11.useRef)(performFetch);
2787
+ performFetchRef.current = performFetch;
2778
2788
  (0, import_react11.useEffect)(() => {
2779
- if (!fetchOnMount && data.length === 0 && !isLoading) return;
2789
+ if (!fetchOnMount && !hasFetchedRef.current) return;
2780
2790
  if (debounceTimerRef.current) clearTimeout(debounceTimerRef.current);
2781
2791
  debounceTimerRef.current = setTimeout(() => {
2782
- performFetch();
2792
+ performFetchRef.current();
2783
2793
  }, debounceMs);
2784
2794
  return () => {
2785
2795
  if (debounceTimerRef.current) clearTimeout(debounceTimerRef.current);
2786
2796
  };
2787
- }, [currentPage, itemsPerPage, sortConfig, filters, externalFilters, reloadTrigger, fetchOnMount, performFetch, data.length, isLoading, debounceMs]);
2797
+ }, [currentPage, itemsPerPage, sortConfig, filters, externalKey, reloadTrigger, fetchOnMount, debounceMs]);
2788
2798
  const renderFilterInput = (col) => {
2789
2799
  if (!col.filter) return null;
2790
2800
  if (col.type === "boolean") {