@smallwebco/tinypivot-react 1.0.13 → 1.0.14

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
@@ -67,13 +67,17 @@ function useExcelGrid(options) {
67
67
  const [columnVisibility, setColumnVisibility] = (0, import_react.useState)({});
68
68
  const [globalFilter, setGlobalFilter] = (0, import_react.useState)("");
69
69
  const [columnStatsCache, setColumnStatsCache] = (0, import_react.useState)({});
70
+ const dataSignature = (0, import_react.useMemo)(
71
+ () => `${Date.now()}-${Math.random().toString(36).slice(2)}`,
72
+ [data]
73
+ );
70
74
  const columnKeys = (0, import_react.useMemo)(() => {
71
75
  if (data.length === 0) return [];
72
76
  return Object.keys(data[0]);
73
77
  }, [data]);
74
78
  const getColumnStats = (0, import_react.useCallback)(
75
79
  (columnKey) => {
76
- const cacheKey = `${columnKey}-${data.length}`;
80
+ const cacheKey = `${columnKey}-${dataSignature}`;
77
81
  if (!columnStatsCache[cacheKey]) {
78
82
  const stats = (0, import_tinypivot_core.getColumnUniqueValues)(data, columnKey);
79
83
  setColumnStatsCache((prev) => ({ ...prev, [cacheKey]: stats }));
@@ -81,11 +85,14 @@ function useExcelGrid(options) {
81
85
  }
82
86
  return columnStatsCache[cacheKey];
83
87
  },
84
- [data, columnStatsCache]
88
+ [data, columnStatsCache, dataSignature]
85
89
  );
86
90
  const clearStatsCache = (0, import_react.useCallback)(() => {
87
91
  setColumnStatsCache({});
88
92
  }, []);
93
+ (0, import_react.useEffect)(() => {
94
+ clearStatsCache();
95
+ }, [dataSignature, clearStatsCache]);
89
96
  const columnDefs = (0, import_react.useMemo)(() => {
90
97
  return columnKeys.map((key) => {
91
98
  const stats = getColumnStats(key);