@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.js CHANGED
@@ -2677,36 +2677,46 @@ function ITDataTable({
2677
2677
  handleItemsPerPageChange
2678
2678
  } = useTableState({ defaultItemsPerPage });
2679
2679
  const debounceTimerRef = useRef4(null);
2680
+ const hasFetchedRef = useRef4(false);
2681
+ const fetchDataRef = useRef4(fetchData);
2682
+ fetchDataRef.current = fetchData;
2683
+ const externalFiltersRef = useRef4(externalFilters);
2684
+ externalFiltersRef.current = externalFilters;
2685
+ const externalKey = JSON.stringify(externalFilters);
2680
2686
  const computedTotalPages = Math.ceil(totalItems / itemsPerPage) || 1;
2681
2687
  const performFetch = useCallback5(async () => {
2682
2688
  setIsLoading(true);
2683
2689
  try {
2684
- const response = await fetchData({
2690
+ const response = await fetchDataRef.current({
2685
2691
  page: currentPage,
2686
2692
  limit: itemsPerPage,
2687
- filters: { ...filters, ...externalFilters },
2693
+ filters: { ...filters, ...externalFiltersRef.current },
2688
2694
  sort: sortConfig || void 0
2689
2695
  });
2690
2696
  setData(response.data || []);
2691
2697
  setTotalItems(response.total || 0);
2698
+ hasFetchedRef.current = true;
2692
2699
  } catch (error) {
2693
2700
  console.error("ITDataTable: Error fetching data", error);
2694
2701
  setData([]);
2695
2702
  setTotalItems(0);
2703
+ hasFetchedRef.current = true;
2696
2704
  } finally {
2697
2705
  setIsLoading(false);
2698
2706
  }
2699
- }, [currentPage, itemsPerPage, filters, sortConfig, fetchData, externalFilters]);
2707
+ }, [currentPage, itemsPerPage, filters, sortConfig]);
2708
+ const performFetchRef = useRef4(performFetch);
2709
+ performFetchRef.current = performFetch;
2700
2710
  useEffect5(() => {
2701
- if (!fetchOnMount && data.length === 0 && !isLoading) return;
2711
+ if (!fetchOnMount && !hasFetchedRef.current) return;
2702
2712
  if (debounceTimerRef.current) clearTimeout(debounceTimerRef.current);
2703
2713
  debounceTimerRef.current = setTimeout(() => {
2704
- performFetch();
2714
+ performFetchRef.current();
2705
2715
  }, debounceMs);
2706
2716
  return () => {
2707
2717
  if (debounceTimerRef.current) clearTimeout(debounceTimerRef.current);
2708
2718
  };
2709
- }, [currentPage, itemsPerPage, sortConfig, filters, externalFilters, reloadTrigger, fetchOnMount, performFetch, data.length, isLoading, debounceMs]);
2719
+ }, [currentPage, itemsPerPage, sortConfig, filters, externalKey, reloadTrigger, fetchOnMount, debounceMs]);
2710
2720
  const renderFilterInput = (col) => {
2711
2721
  if (!col.filter) return null;
2712
2722
  if (col.type === "boolean") {